I can't find something that'll lead in the right direction. Everyone else's similar issues with nested resources seems to resolve around accepts_nested_attributes_for… which I'm not trying to do. I'm not trying to save children from the parent, I'm trying to save directly from the child.
In my routes.rb, I have nested my resource
resources :parents, param: :parent do
resources :children, param: :child
end
parent and child tables both have their own id column, but also have unique index on columns parent and child respectively, which I was to be used in the URL instead of the id.
This is working fine browsing around going to the show, edit and index actions of each controller.
The problem is there are exceptions saving data.
I'm hoping the root-cause of the issue doesn't come down to a field in the child table is also called child as that's what I've used to override to_param in the model and need to keep it that way.
Navigating to the edit screen: http://ift.tt/1HoWN5u and pushing submit on the form, returns this NoMethodError exception:
NoMethodError at /parents/harry/children/sally
undefined method `permit' for "sally":String
I'm sure the problem is something to do with how my Strong Parameters line is in children_controller.rb. Can I add to require a hash of :parent and :child maybe?
def children_params
params.require(:child).permit(:child, :date_of_birth, :nickname)
end
Update 1 (Added params): Here are the request parameters:
{
"utf8"=>"✓",
"_method"=>"patch",
"authenticity_token"=>"fAkBvy1pboi8TvwYh8sPDJ6n2wynbHexm/MidHruYos7AqwlKO/09kvBGyWAwbe+sy7+PFAIqKwPouIaE34usg==",
"child"=>"sally",
"commit"=>"Update Child",
"controller"=>"children",
"action"=>"update",
"parent_parent"=>"harry"
}
Other instance variable in-scope at time of error:
@parent
<Parent id: 1, parent: "harry", description: "", user_id: 1, created_at: "2015-06-27 12:00:15", updated_at: "2015-06-27 12:00:15">
@child
<Child id: 1, child: "sally", date_of_birth: nil, parent_id: 1, nickname: nil, created_at: "2015-06-27 12:00:15", updated_at: "2015-06-27 12:00:15">
Aucun commentaire:
Enregistrer un commentaire