Forum: Ruby on Rails Order parents when displaying children question

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Maarten H. (Guest)
on 2006-05-30 10:29
Hi,

I want to show a series of links belonging to a specific category.
The links will be shown grouped by category, but how can I alter the
order of the categories?

I have a field in my database called position with the order in which
they
should appear.

MODELS:

class Category < ActiveRecord::Base

  has_many :links
  validates_uniqueness_of :category, :message => "already exists"

end

class Link < ActiveRecord::Base

  belongs_to :category
  validates_associated :category
  validates_presence_of :link
  validates_presence_of :url

  def self.get_links
    find(:all, :order => :category_id)
  end

end

Any help would be great!

Maarten
This topic is locked and can not be replied to.