Topic: Problem Polymorphic Relationships using Attachment_fu

I am having problems with the view. I am getting a NoMethodError in Buildings#index
undefined method `public_filename' for #<Class:0x1ee5704>.

Please help!

See code below:
-------------------

#[Models - asset.rb]

class Asset < ActiveRecord::Base
  belongs_to :resource, :polymorphic=>true
end

#[Models - building_shots.rb]

class BuildingShot < Asset
  belongs_to :building
 
 
  has_attachment     :content_type => :image,
                     :storage => :file_system,
                     :processor => 'ImageScience',
                     :max_size => 1.megabytes,
                     :resize_to => '800x600>',
                     :size => 1..5.megabyte,
                     :thumbnails => { :thumbnail => '100x100>' }

      validates_as_attachment

end



#[Models - building.rb]

class Building < ActiveRecord::Base
  has_many :building_shots, :as => :resource,  :dependent => :destroy

end

#[Controller - buildings_controller.rb]

def index
    @buildings = Building.find(:all)

    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @buildings }
    end
  end



#[Buildings View - index.html.erb]
<% for building in @buildings %>

    <div  class="result-image"><%=building.building_shots.public_filename%></div>
<% end%>

Re: Problem Polymorphic Relationships using Attachment_fu

I see a couple mistakes here.

1) Remove belongs_to :building from your BuildingShot class. You've already defined the parent association in the Asset class.
2) You have the class name erroneously pluralized in the view. It should be <%=building.building_shot.public_filename%>