I am just trying to work through David Black’s block of code from Ruby
For Rails, on page 80.
def all
@order = params[:order] || “number”
sort_proc = case @order
when “author” then lambda {|r| [r.user.name.downcase, r.number] }
when “status”,“title” then lambda {|r| [r.send(@order).downcase,
r.number]}
when “number” then lambda {|r| -r.number }
end
@rcrs = Rcr.find(:all).sort_by &sort_proc
end
I can get this to work just fine. But how about this…if the user
passes the “order” parameter as author, I want to sort nearly the same
way, but with r.user.name descending. I know this errors, but I mean
something like:
when “author” then lambda {|r| [r.user.name.downcase DESC,
r.number] }
How do you control the ascending/descending on one of the two sort
parameters?
Also, in the “number” sort option, what is the - doing in the part
-r.number? I have experimented with it, but haven’t determined what it
is doing.
Thanks,
Rob