I want json output order by id(child id)
Can I solve this problem ?
this is some code in my project
show.json.rabl (I used Rabl)
object @book
attributes :id , :name
child :questions do
attributes :id , :name
end
books_controller.rb
def show
@book = Book.find(params[:id])
end
Sorry for my English , Thank you.
It depends on your app and what you want to accomplish, but you could define a
default_scopein theQuestionmodel like this:Or you could define a
default_scopein theBookmodel:If you want eager load the
questions, then useincludesinstead ofjoin.