views:

177

answers:

1

The acts_as_ordered plugin isn't ordering records in my Ruby on Rails app.

I have the following models

quiz.rb

class Quiz < ActiveRecord::Base
  acts_as_ordered :order => 'created_at DESC'
  validates_presence_of :name, :user_id

  belongs_to :user
  has_many :questions

  before_destroy :delete_questions
end

question.rb

class Question < ActiveRecord::Base
  acts_as_ordered :scope => :Quiz, :order => 'question_order'
  validates_presence_of :quiz_id

  belongs_to :quiz
end

I've installed the acts_as_ordered plugin from http://svn.viney.net.nz/things/rails/plugins/acts_as_ordered

As far as I can see the following should work in the quizzes/edit.html.erb view (it's actually in a partial but I don't think that's too relevant)

<table>
  <% for question in @quiz.questions %>
    <tr>
      <td><%= question.question_order %>. <%= question.question_text %></td>
    </tr>
  <% end %>
</table>

The trouble is the questions are not being displayed in 'question_order'.

I've used this plugin before and had it working with the find command.

Does acts_as_ordered work in this context?

+1  A: 

I think you have the wrong plugin for your purposes... Acts As Ordered is for finding next/previous records from a single found record, not for ordering a list of associations.

I believe the one you're looking for is acts as list

Andrew Vit
Thanks for that, solved the problem
Matt Haughton