Answer the question
In order to leave comments, you need to log in
What is the correct way to write WHERE in Rails?
Good afternoon, I apologize in advance if my question seems stupid to you - I'm still new to rails.
There is a Wedding model, to which photos (another model) are attached using the Paperclip gem.
To display, for example, the first photo, I do this:
#в контроллере
@wedding = Wedding.last
#во вьюхе
<%= image_tag @wedding.photos[0].image.url(:medium) %>
Answer the question
In order to leave comments, you need to log in
=image_tag @wedding.photos[0].image.url(:medium) unless @wedding.photos.empty?
scope :with_photos, -> { joins(:photos).where('photos.empty? = ?', false) }
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question