The rails path to new returns does not match the routes when the parent is not passed

I want to have a page on which I create a new account ( views / accounts / new.html.erb ), but when I link to this page, I get an error that the parent object (like kid) id is missing.

 <%= link_to (t 'add_account'), new_kid_account_path, :class => 'btn btn-primary' %>

Error message:

There are no route mappings {: action => "new" ,: controller => "accounts"} missing required keys: [: kid_id]

In my active record - the account belongs to the kids, and the baby has a lot of accounts.

I don’t want to pass the kid id, but instead I want the user to select the kid id or create a new baby on the new account page.

How to do it?

+4
2

, new_kid_account_path :

new_kid_account_path(:kid_id => @kid.id)

, , , . , kid_id - ", ", kid_id link_to

+1

, . kids_controller.rb :

before_filter :get_kid

private
def get_kid
  @kid = params[:id].blank? ? Kid.new : Kid.find(params[:id])
end

, , .

:

post 'new_kid', to: 'kids#new', as: new_kid_account

. , : kid_id .

+1

All Articles