Crazy looping in render partial

Controller:

Personcontroller.rb

def index
@picks =Product.find_person(session[:user_id])
#@[email protected]
@picks.sort_by{|x| x.id}.reverse
render :partial => “pick”, :collection => @picks
end

View:

_pick.rhtml

<% for pick in @picks %>
<IMG SRC="<%=
pick.image_url1%>" ALT="" WIDTH=90 HEIGHT=90 BORDER=10

<% 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.

Ouch… why use an 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 C. [email protected]

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, “[email protected]

On Jan 18, 2007, at 7:13 AM, Bontina C. wrote:

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

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 B. http://agileconsultingllc.com
[email protected]
Skype: rob.biedenharn

On Jan 18, 2007, at 7:13 AM, Bontina C. wrote:

Controller:

Personcontroller.rb

def index
@picks =Product.find_person(session[:user_id])
#@[email protected]
@picks.sort_by{|x| x.id}.reverse
render :partial => “pick”, :collection => @picks
end

And 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 B. http://agileconsultingllc.com
[email protected]
Skype: rob.biedenharn

Thank you for cleaning up the puzzles.

[email protected] 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, “[email protected]

Thanks for all the suggestions.
My code is (hopefully XD) now a little more beautiful.

Abon

HAHA! You’re predicting my posting behavior.
Thanks for the correction and the suggestion about the naming
convention.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs