这是我的routes.rb
resources :subjects, :shallow => true do
resources :skills, :only => [:new, :create]
end
resources :skills
这是我的相关控制器(SkillsController)
def new
# if action is called by new_subject_skill_path then
# subject_id is not nil
if params[:subject_id]
@subject = Subject.find(params[:subject_id])
end
@skill = Skill.new
end
这是相关的观点:(/views/subject/show.html.erb)
<%= link_to 'Add new skill', new_subject_skill_path %>
这是我运行佣金路线
时的结果new_subject_skill GET /subjects/:subject_id/skills/new(.:format) skills#new
然而,当我尝试渲染视图时,我收到以下错误
No route matches {:action=>"new", :controller=>"skills"}
我做错了什么?
干杯: - )
答案 0 :(得分:0)
我刚想通了 - 我忘了将@subject添加到link_to方法。
<%= link_to 'Add new skill', new_subject_skill_path(@subject) %>