Hi!! I have a few models that use a Photo polymorphic model. It''s all good and fine for saving or accessing the photos'' attributes via console or inspect or logger, but if I try to call them directly in the view with, for example, @banner.photo.file, it returns a undefined method ''file'' etc for nil:Nil Photos are being uploaded via paperclip and all models are set with has_one :photo, :as => :imageable and accepts_nested_attributes_for :photo, :allow_destroy => true. And the Photo model is set as belongs_to :imageable, :polymorphic => true and has_attached_file :file. These are the columns for the Photo model: id:integer file:string imageable_id:integer imageable_type:string file_file_name:string file_content_type:string file_file_size:integer (besides created_at etc) In my view: <% @banners.each do |b| %> <%= b.photo.inspect %><br /> <% end %> You can see the inspect at http://bdyvu2.hospedagemweb.net/ Many thanks in advance!! Going out of my mind here!! (been at it for days!) -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Colin Law
2012-Jan-27 10:10 UTC
Re: Can''t access polymorphic associated model''s attributes
On 26 January 2012 18:38, Yara Mayer <yaramayer-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi!! > > I have a few models that use a Photo polymorphic model. It''s all good > and fine for saving or accessing the photos'' attributes via console or > inspect or logger, but if I try to call them directly in the view > with, for example, @banner.photo.file, it returns a undefined method > ''file'' etc for nil:NilThat means that @banner.photo is nil. Add code to your view to test @banner.photo before accessing @banner.photo.file. Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Yara Mayer
2012-Feb-02 17:11 UTC
Re: Can''t access polymorphic associated model''s attributes
oh hi! I did... I can see it if I inspect @banner.photo, but if I try to access it directly (using any of the name variations), it doesn''t work - for ANY of the attributes :/ thankss, yara -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Colin Law
2012-Feb-02 17:25 UTC
Re: Re: Can''t access polymorphic associated model''s attributes
On 2 February 2012 17:11, Yara Mayer <yaramayer-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> oh hi! > I did... I can see it if I inspect @banner.photo, but if I try to > access it directly (using any of the name variations), it doesn''t work > - for ANY of the attributes :/Please quote the previous message when replying and insert your reply into the previous message so that we don''t have to find the previous mail to know what you are talking about. Thanks. You say that @banner.photo works but accessing it directly does not, what do you mean by that? You could copy and paste the console output showing the inspect and explain what you mean by "doesn''t work". Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.