Hi, I am working on a project that is using Paperclip to upload multiple images to an Asset model. my Post model has_many Assets. As per this tutorial/screencast... https://github.com/Emerson/Multiple-File-Uploads-with-Paperclip-and-Rails-3/blob/master/app/views/posts/show.html.erb"> http://www.emersonlackey.com/article/paperclip-with-rails-3> This all works fine and I can add/delete multiple images to a post perfectly. I can also display multiple images for each post in the show view using this code... ///////////<code>//////////////// <div class="thumb"> <% for asset in @post.assets %> <%= link_to image_tag(asset.asset.url(:thumb)), asset.asset.url(:original) %> <% end %> </div> ///////////</code>//////////////// What I want to be able to do is display 1 or more images for each of the records in index.html but I can''t make that code work in index ... anyone got any any idea how I can do this? Cheers for any help! -- Posted via http://www.ruby-forum.com/. -- 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.
On Mar 20, 2012, at 9:45 AM, Graham Dawe wrote:> Hi, > > I am working on a project that is using Paperclip to upload multiple > images to an Asset model. my Post model has_many Assets. As per this > tutorial/screencast... > > https://github.com/Emerson/Multiple-File-Uploads-with-Paperclip-and-Rails-3/blob/master/app/views/posts/show.html.erb"> > > http://www.emersonlackey.com/article/paperclip-with-rails-3> > > This all works fine and I can add/delete multiple images to a post > perfectly. I can also > display multiple images for each post in the show view using this > code... > > ///////////<code>//////////////// > > <div class="thumb"> > <% for asset in @post.assets %> > > <%= link_to image_tag(asset.asset.url(:thumb)), > asset.asset.url(:original) %> > > <% end %> > </div> > > ///////////</code>//////////////// > > What I want to be able to do is display 1 or more images for each of the > records in index.html but I can''t make that code work in index ... > anyone got any any idea how I can do this? > > Cheers for any help!Let''s say you are looping over your Post objects in the index page, and you want to show the first image for each post: <% for post in @posts %> <tr><td> <%= image_tag(post.assets.first.url(:thumb)) %> </td><td> ...whatever else you show in the index about each post </td></tr> <% end %> The key thing here is that post.assets is a collection of all related assets. Walter> > -- > Posted via http://www.ruby-forum.com/. > > -- > 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. >-- 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.
> <% for post in @posts %> > <tr><td> > <%= image_tag(post.assets.first.url(:thumb)) %> > </td><td> > ...whatever else you show in the index about each post > </td></tr> > <% end %> > > The key thing here is that post.assets is a collection of all related > assets. > > WalterThanks for your reply Walter. I have tried what you suggested but I get the following ... undefined method `url'' I think I had tried the way you suggested previously but with the same result. -- Posted via http://www.ruby-forum.com/. -- 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.
On Mar 20, 2012, at 11:44 AM, Graham Dawe wrote:>> <% for post in @posts %> >> <tr><td> >> <%= image_tag(post.assets.first.url(:thumb)) %> >> </td><td> >> ...whatever else you show in the index about each post >> </td></tr> >> <% end %> >> >> The key thing here is that post.assets is a collection of all related >> assets. >> >> Walter > > Thanks for your reply Walter. I have tried what you suggested but I get > the following ... > > undefined method `url'' > > I think I had tried the way you suggested previously but with the same > result.Okay, the confusion is arising because you have a relationship named asset, and within that, a property named asset. Try this: post.assets.first.asset.url(:thumb). Walter> > -- > Posted via http://www.ruby-forum.com/. > > -- > 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. >-- 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.
Thank you very much for your help Walter! That has solved it and I have hopefully learnt something very useful :) -- Posted via http://www.ruby-forum.com/. -- 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.