Nested resources with independent views model name error in Ruby on Rails -


in routes:

resources :users   resources :service_exps end 

user model:

has_many :service_exps 

service_exps model:

belongs_to :user 

in service_exps controller new action:

def new   user = user.find(params[:user_id])   @service_exp = user.service_exps.build   render :layout => false end   

in service_exps form:

= form_for ([@service_exp.user, @service_exp]), :remote => true |s|  .modal-body   .row     .span       = s.label :org_name       = s.text_field :org_name, :class => "span3"   .row     .span       = s.label :position       = s.text_field :position, :class => "span3"     .actions     = s.submit 'save',:class => "btn btn-info" 

it give error

 undefined method `user' nil:nilclass 

please give suggestion solve this. thanks!

these type of errors pretty easy debug. error msg says everything. calling method (in case 'user') on nil object.

follow these steps:

  • find file , line no error msg.
  • find object nil.
  • confirm object initialized properly

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -