Skip to content

Instantly share code, notes, and snippets.

@joselo
Created January 10, 2012 17:16
Show Gist options
  • Save joselo/1590075 to your computer and use it in GitHub Desktop.
Save joselo/1590075 to your computer and use it in GitHub Desktop.
# En el model.rb, nota que cambie created_at DESC por ASC
has_many :image_models, :as => :owner, :dependent => :destroy, :order => 'created_at ASC'
# agrega este metodo en le modelo model.rb
def first_image_permalink
image = image_models.first
image.permalink if image && !image.document_file_name.blank?
end
#Finalmente de la vista se llamaria asi
<% @models.each do |model| %>
<%= image_tag model.first_image_permalink %>
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment