在路線:嵌套資源與Ruby的獨立意見型號名稱錯誤on Rails的
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
請給予任何建議來解決這個問題。謝謝!
您確定您要達到service_exps控制器的新操作嗎? – 2013-05-10 05:36:50
hey santhosh,如果在@ service_exp.user上單擊(ctrl + click),它會轉到新的操作。 – Rajeev 2013-05-10 05:52:34