rubyonrailsin

A Ruby and Rails talk

Thursday, March 25, 2010


[Rails] Re: Order by an h_m_t association, pushing a value to the top

by rubyonrailsin 0 comments

Tag


Share this post:
Design Float
StumbleUpon
Reddit

Hi rob, thanks. I actually tried my pseudo-code and it worked, with the
addition of putting 'desc' at the end. Ie, this:

@quizzes = Quiz.paginate(:all, :conditions => <conditions>, :order =>
"(tags.name = 'banana' or tags.name) desc", :page => params[:page],
:per_page
=> 25)

The desc is necessary because "tags.name = 'banana'" comes out as 1 or 0
and we want the 1s to be shown before the 0s. But you know that as
that's why you set 'A' or 'Z' as the result of the test.

I like your solution though, it's more obvious to the reader what is
going on. Although i also like mine as it only involves changing the
'order' option and nothing else. :) Ultimately i guess we're doing the
same thing though.
--
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@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment

Subscribe feeds via e-mail

Blog Archive