problem using default_scope on a model table

Posted by DannyRe on Stack Overflow See other posts from Stack Overflow or by DannyRe
Published on 2011-02-26T23:20:15Z Indexed on 2011/02/26 23:25 UTC
Read the original article Hit count: 205

Hey. In my controller/index action I use the following query:

@course_enrollments = current_user.course_enrollments

This is what my table looks like. It is referencing a course table. The course table has a colum 'title'.

create_table "course_enrollments", :force => true do |t|
  t.integer  "user_id",    :null => false
  t.integer  "course_id",  :null => false
  t.datetime "created_at"
  t.datetime "updated_at"
end

I want to be able to order my course_enrollments by course in my index view. Furthermore Id like to do a default_scope in my model, like this:

  default_scope :order => 'title asc'

any suggestions? Thx for your time

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about ruby-on-rails-3