Alejandro, Thank you for taking the time to answer my question and you where right. just by refering the asset object by assetfield.asset.url(:thumb) it worked perfect.
On 28 jul, 15:27, Alejandro Cadavid <[email protected]> wrote: > Hey > > When you do (user.assets.each do |assetfield|) you are getting each Asset > object associated to user in the assetfield variable, but still you need to > access the attachment property which is 'asset'. So basically you just need > to change assetfield.url(:thumb) for assetfield.asset.url(:thumb) and it > should work fine. Check that this is done in the edit form > as asset_fields.object.asset.url(:thumb) (where asset_fields.object > represents the same Asset object as assetfield) > > Hope this helps. Good luck! > > > > > > > > On Thu, Jul 28, 2011 at 5:34 AM, Daniel Amsterdam <[email protected]> wrote: > > 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) %></td> > > <td><%= f.label :destroy, 'Verwijder' > > %></td> > > <td><%= asset_fields.check_box(:_destroy) > > %></td> > > </tr> > > <% 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| %> > > <div id="<%= user.id %>" class="profile_box"> > > <%= 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! > > > -- > > 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 [email protected]. > > To unsubscribe from this group, send email to > > [email protected]. > > For more options, visit this group at > >http://groups.google.com/group/rubyonrails-talk?hl=en. -- 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 [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

