Images patch relative to [custom] view directory
In my Rails application, user may have custom page templates (not for the application) which are stored in public/user_templates/user1/
the view .erb file is also stored there in the user template folder. There is an images folder inside every template folder. How can I use the relative paths of the images in the .erb file?
For example <img src"imag开发者_C百科es/image1" />
Thanks, Imran
You can't access static files inside of your app directory without passing them through a route somehow. You should create a directory for each user_id in the public/images folder of your application, then store the images for each user there. Then you can access those images at <img src="images/#{user_id}/image1.jpg" />
or with a view helper image_tag "#{user_id}/image1.jpg"
Depending on your application, you may want to use Paperclip
精彩评论