在路线:
resources :users do
resources :service_exps
end
用户模型:
has_many :service_exps
service_exps 模型:
belongs_to :user
在 service_exps 控制器中的新操作:
def new
user = User.find(params[:user_id])
@service_exp = user.service_exps.build
render :layout => false
end
在 service_exps 形式中:
= form_for ([@service_exp.user, @service_exp]), :remote => true do |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"
它给出错误
undefined method `user' for nil:NilClass
请提出任何解决此问题的建议。谢谢!