Hello,
i’m trying out Rails 3 and i’ve created a little app with paperclip.
My problem is that i cant get the assets for a user in the index
action but in the edit action it works. i have the flowing set up
class User
has_many :assets
class Asset
belongs_to :user
has_attached_file :asset,
:styles => { :medium => “300x300>”,
:thumb => “100x100>” }
In my edit action i can get the assets for the user easy by doing:
<% f.fields_for :assets do |asset_fields| %>
<% unless asset_fields.object.new_record? %>
<tr>
<td><%= link_to
image_tag(asset_fields.object.asset.url(:thumb)),
asset_fields.object.asset.url(:original) %>
<% end %>
<% end %>
Now in my index action i want to display the user.assets also but i
get the error undefined method `url’ for xx
in the user controler i get the users by
@users = User.all(:include => :assets)
#@users = User.all()
in the view i have
<% @users.each do |user| %>
<%= user.firstname %><%= user.lastname %>
<%= debug(user) %>
<% unless current_user.nil? %>
<% if current_user.id == user.id %>
<%= link_to “Edit”, edit_user_path(user) %>
<% end %>
<% end %>
<%= debug(user.assets) %>
<% user.assets.each do |assetfield| %>
<%= assetfield.url(:thumb) %>
<% end %>
</div>
<% end %>
and i get the error undefined method `url’ for #<Asset:
0x000001058cce08> so the asset object is not there i gues. I’m having
trouble to understand whats wrong because the realtion is fine. I hop
somebody here can help me understand this and help me out?
thanks in advance!