Antonio Moreno wrote in post #1155440:
> Now, I want to order the associated records:
>
> has_many :children, dependent: :destroy, -> { order 'id asc' } do
>
> but this raises an error:
>
> SyntaxError in ParentsController#index
> has_many :children, dependent: :destroy, -> { order 'id asc' } do
This line looks wrong to me. You have a lambda arrow (-> with it's block
{ ... } and immediately trying to open another block with do. Written a
slightly different way it might look something like:
has_many :children, dependent: :destroy, -> do order 'id asc' end do
Here's an example that maybe shows what you're trying to do:
has_many :tracks, -> { order "position" }, dependent: :destroy
In this case it appear to me the lambda function is in the "scope"
argument with options following and no block.
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/64f8c9a3e29070cdb54c4d41d7e7c421%40ruby-forum.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment