Controller: Personcontroller.rb def index @picks =Product.find_person(session[:user_id]) #@picks=@pickstemp.uniq @picks.sort_by{|x| x.id}.reverse render :partial => "pick", :collection => @picks end View: _pick.rhtml <% for pick in @picks %> <A HREF="http://example.com/admin/show/<%=pick.id%>"><IMG SRC="<%pick.image_url1%>" ALT="" WIDTH=90 HEIGHT=90 BORDER=10</A> <% end %> I suppose I should get each pick once in the view./personal But it generates an html repeating @picks over and over again until the page is full. Am I missing any parameter here so it behaves like this? Any help are highly appreciated. -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
augustlilleaas-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Jan-18 12:22 UTC
Re: Crazy looping in render partial
Ouch.. why use an <a> tag? Do this instead: <%= link_to image_tag(pick.image_url1, :width => 90, :height => 90, :border => 10), :controller => "admin", :action => "show", :id => pick %> On Jan 18, 1:13 pm, Bontina Chen <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Controller: > > Personcontroller.rb > > def index > @picks =Product.find_person(session[:user_id]) > #@pic...-psI9yc63292WmTTHyLM6Qg@public.gmane.org > @picks.sort_by{|x| x.id}.reverse > render :partial => "pick", :collection => @picks > end > > View: > > _pick.rhtml > > <% for pick in @picks %> > <A HREF="http://example.com/admin/show/<%=pick.id%>"><IMG SRC="<%> pick.image_url1%>" ALT="" WIDTH=90 HEIGHT=90 BORDER=10</A> > <% end %> > > I suppose I should get each pick once in the view./personal > But it generates an html repeating @picks over and over again until the > page is full. > > Am I missing any parameter here so it behaves like this? > > Any help are highly appreciated. > > -- > Posted viahttp://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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
augustlilleaas-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Jan-18 12:25 UTC
Re: Crazy looping in render partial
Oh, by the way, I''d say @picks = Product.find_person(session[:user_id], :order => "id").reverse is better than doing @pics.sort_by later on. Whats the output of @picks.inspect? On Jan 18, 1:22 pm, "augustlille...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" <augustlille...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Ouch.. why use an <a> tag? Do this instead: > > <%= link_to image_tag(pick.image_url1, :width => 90, :height => 90, > :border => 10), :controller => "admin", :action => "show", :id => pick > %> > > On Jan 18, 1:13 pm, Bontina Chen <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: > > > Controller: > > > Personcontroller.rb > > > def index > > @picks =Product.find_person(session[:user_id]) > > #@pic...-psI9yc63292WmTTHyLM6Qg@public.gmane.org > > @picks.sort_by{|x| x.id}.reverse > > render :partial => "pick", :collection => @picks > > end > > > View: > > > _pick.rhtml > > > <% for pick in @picks %> > > <A HREF="http://example.com/admin/show/<%=pick.id%>"><IMG SRC="<%> > pick.image_url1%>" ALT="" WIDTH=90 HEIGHT=90 BORDER=10</A> > > <% end %> > > > I suppose I should get each pick once in the view./personal > > But it generates an html repeating @picks over and over again until the > > page is full. > > > Am I missing any parameter here so it behaves like this? > > > Any help are highly appreciated. > > > -- > > Posted viahttp://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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Jan 18, 2007, at 7:13 AM, Bontina Chen wrote:> Controller: > > Personcontroller.rb > > def index > @picks =Product.find_person(session[:user_id]) > #@picks=@pickstemp.uniq > @picks.sort_by{|x| x.id}.reverse > render :partial => "pick", :collection => @picks > end > > View: > > _pick.rhtml > > <% for pick in @picks %> > <A HREF="http://example.com/admin/show/<%=pick.id%>"><IMG SRC="<%> pick.image_url1%>" ALT="" WIDTH=90 HEIGHT=90 BORDER=10</A> > <% end %> > > I suppose I should get each pick once in the view./personal > But it generates an html repeating @picks over and over again until > the > page is full. > > Am I missing any parameter here so it behaves like this? > > Any help are highly appreciated.Change it to: _pick.rhtml <A HREF="http://example.com/admin/show/<%=pick.id%>"><IMG SRC="<%= pick.image_url1%>" ALT="" WIDTH=90 HEIGHT=90 BORDER=10 /></A> The :collection part of the render implies the loop "for pick in @picks" (actuallly, the @picks comes from the :collection and the ''pick'' from the :partial). And you probably should use link_to(image_tag(...), ...) as previously suggested. -Rob Rob Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org Skype: rob.biedenharn --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Jan 18, 2007, at 7:13 AM, Bontina Chen wrote:> Controller: > > Personcontroller.rb > > def index > @picks =Product.find_person(session[:user_id]) > #@picks=@pickstemp.uniq > @picks.sort_by{|x| x.id}.reverse > render :partial => "pick", :collection => @picks > endAnd to possibly save you your next message, @picks.sort_by{|x| x.id}.reverse doesn''t change @picks. Perhaps you want: def index @picks =Product.find_person(session[:user_id]).sort_by {|p| - p.id } render :partial => "pick", :collection => @picks end Note the use of ''- p.id'' to reverse the order in one step. It also seems odd (to me at least) that "find_person" returns more than one object since it is singular; "find_people" might be clearer. Of course, that just makes me wonder why the Product model is finding a Person at all. -Rob Rob Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org Skype: rob.biedenharn --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thank you for cleaning up the puzzles. -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
augustlilleaas-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote:> Oh, by the way, I''d say @picks = Product.find_person(session[:user_id], > :order => "id").reverse is better than doing @pics.sort_by later on. > > Whats the output of @picks.inspect? > > On Jan 18, 1:22 pm, "augustlille...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org"Thanks for all the suggestions. My code is (hopefully XD) now a little more beautiful. Abon -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
HAHA! You''re predicting my posting behavior. Thanks for the correction and the suggestion about the naming convention. -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---