SQL

Rails find :conditions

The Class ActiveRecord::Base provides an interesting method to execute searches on the database without the need to write SQL queries. It is the find method.

The find method has some retrieval options (:all, :first, :last, :id) and many parameters which are detailed in the links above. In this article we'd like to focus on the :conditions parameter.

Ruby on Rails Order By Using Associated Model

It is very easy to use an 'order by' clause in a model in Ruby on Rails. Supposing you have a Category model it's as simple as doing this:
 
@categories = Category.find(:all, :order => 'title')
 
But what if I need to order by the title of the subcategories after ordering by the categories title?
 
Using the category_id does not work either, because it almost sure that the categories will not be added in alphabetical order, so the command below does not work for me either:
 

Syndicate content