ruby - Access polymorphic attribute in the view -


trying work out small issue, have got polymorphic association working cant seem figure out how show image in view once record has been saved.

my setup

class image < activerecord::base belongs_to :imageable, polymorphic: true  attr_accessible :photo has_attached_file :photo, :styles => { :small_blog => "250x250#", :large_blog => "680x224#", :thumb => "95x95#" } end  class post < activerecord::base  has_many :images, as: :imageable  accepts_nested_attributes_for :images attr_accessible :comments, :title, :images_attributes  end 

so in view have @ moment, throwing undefined method 'photo' error

<% @posts.each |p| %> <%= image_tag(p.photo.url(:large_blog), :class => 'image') %> <% end %> 

any pointers appreciated

post has many images, , each image has photo. can go this:

<% @posts.each |p| %>    <% p.images.each |i| %>     <%= image_tag(i.photo.url(:large_blog), :class => 'image') %>   <% end %> <% end %> 

Comments

Popular posts from this blog

matlab - Deleting rows with specific rules -

php - MySQLi multi_query results for later use -