我读了一本名为“Rails 3 in Action”的书,做了两页:“index”和“new”,设置 routes.rb:
root :to => 'projects#index'
match '/new', to:'projects#new'
和项目控制器:
def new
@project = Project.new
end
def create
@project = Project.new(parmas[:project])
@project.save
flash[:notice] = "Project has been created"
redirect_to @project
end
并查看文件:
index.html.erb
<%= link_to "new", new_path %>
这工作正常,因为我最终在localhost:3000/new
,但问题是:
<%= form_for(@project) do |f| %>
这导致:
#<#:0x416b830> 的未定义方法“projects_path”
项目路径在哪里?当我打印<%= root_path %>
时,我得到了/
,但<%= projects_path %>
给出了错误未定义的方法。
如何定义方法projects_path
?根是不是projects_path
?