开发者

order of records is not proper in heroku

I have a simple test app running on heroku.

But there is an issue in ordering of sub questions.

  class Question < A开发者_Python百科ctiveRecord::Base
    has_many :sub_questions, :class_name => "Question", :foreign_key=>'parent_id'
    belongs_to :main_question, :class_name=> "Question", :foreign_key=>'parent_id'
    accepts_nested_attributes_for :sub_questions, :allow_destroy => true, :reject_if => lambda { |a| a[:content].blank? }
  end  

As you can see from the content on that page: First question, second question , third question and etc.. It has same id in the data base and here is the loop

<% @question.sub_questions.each do |question| %>
     // my code....

<% end %>

The same code/database is working perfectly fine on my local machine. Here is the screenshot from my database. Heroku has same one. I tried restarting the app and everything. Nothin

order of records is not proper in heroku


You have to specify the order you expect.

Example:

has_many :sub_questions, :class_name => "Question", :foreign_key=>'parent_id', :order => "id DESC"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜