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@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

  • Colin Law at Jan 27, 2012 at 10:11 am

    On 26 January 2012 18:38, Yara Mayer 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:Nil
    That 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@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Yara Mayer at Feb 2, 2012 at 5:11 pm
    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@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Colin Law at Feb 2, 2012 at 5:26 pm

    On 2 February 2012 17:11, Yara Mayer 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@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedJan 27, '12 at 9:52a
activeFeb 2, '12 at 5:26p
posts4
users2
websiterubyonrails.org
irc#RubyOnRails

2 users in discussion

Colin Law: 2 posts Yara Mayer: 2 posts

People

Translate

site design / logo © 2022 Grokbase