Ruby on Rails 4 view NoMethodError -
can me figure out doing wrong. seems ruby automagically tries use path dodn't define.
schema.rb
... create_table "packages", force: :cascade |t| t.integer "user_id" t.integer "company_id" t.integer "manager_id" t.string "tag" ... end ...
...
routes.rb
... resources :users resources :packages end ...
packages_controller.rb
... def new @package = package.new @package.user_id = params[:user_id] @package.manager_id = params[:manager_id] || current_user.id @user = safe_find user, @package.user_id, "user" @manager = safe_find user, @package.manager_id, "manager" end ...
new.html.haml
%h1 new package = render 'form' = link_to 'back', user_packages_path(@user)
_form.html.haml
= form_for @package |f| = render 'shared/error_messages', object: f.object -# .field -# = f.label :tag -# = f.text_field :tag -# = render_save_back(user_path(@user))
error received
nomethoderror in packagescontroller#new undefined method `packages_path' #<#<class:0x00000003767c00>:0x007f8b8dcd6228> application trace | framework trace | full trace app/views/packages/_form.html.haml:1:in `_app_views_packages__form_html_haml__2133351491984004824_70118672529040' app/views/packages/new.html.haml:3:in `_app_views_packages_new_html_haml___3329420746374611085_52010540'
= form_for @package |f|
this automagically try turn @package (which of class package) string use path-helper. e.g. @package try call packages_path.
to resolve this, pass resource under package nested, this:
= form_for [@user, @package] |f|
Comments
Post a Comment