Let's say I have the following models:
class Parent < ActiveRecord::Base
has_one :child
end
class Child < ActiveRecord::Base
belongs_to :parent
end
I would like to return the parent through the child, but do the following: I find the model as follows through the controller
@child = Child.find(params[:child_id])
(Not sure if this is relevant, but since I use shallow routing, parent_id is not available in the url)
In my opinion, I would like to get the child parent element as follows:
@child.parent
How should I do it?
Thank!
: ( ) .
belongs_to :parent . . , , , . , .