Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I see two ways :</p> <ul> <li>On top of your rails server, in production and sometimes in dev, you have to use a web server like apache or nginx. With these, you can serve files from other directories for specific URL. E.G. you can make <code>http://yourapp.com/images/</code> serving files from a specific dir. In rails, display the image with a traditionnal <code>image_tag</code></li> </ul> <p>Example with Nginx :</p> <pre><code> # Find the right `server` section which you currently use to serve your rails app server { listen 80; # Add this location /images { root /var/www/my/specific/folder; } location / { #... #... Here you should already some code to proxy to your rails server } } With that, when you access to `yourserver.com/images`, nginx serve your specific folder and not your rails app. Then in your app view : &lt;%= image_tag 'http://yourserver.com/images/my_pic.jpg' %&gt; </code></pre> <ul> <li><p>If you can't access your server settings, you can serve an image file from a controller action with <code>send_file</code></p> <p>In a controller :</p> <pre><code>class ImagesController &lt; ApplicationController def show send_file File.join('/var/www/my/specific/folder',params[:name]), :disposition =&gt; 'inline' end end </code></pre> <p>In <code>config/routes.rb</code></p> <pre><code>match '/images/:name' =&gt; 'images#show', :as =&gt; :custom_image </code></pre> <p>Then when you access this action (via the route you defined in <code>config/routes.rb</code>), you have the image. So in your view you do a traditionnal <code>image_tag</code> with this URL :</p> <pre><code>&lt;%= image_tag custom_image_path( 'my_pic.jpg' ) %&gt; OR &lt;%= image_tag custom_image_url( 'my_pic.jpg' ) %&gt; </code></pre></li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload