我有一个创建项目的基本表格......
<%= form_for(@project, :url => {:action=>'create'}) do |f| %>
<%= f.text_field(:name, {class: "form-control"}) %>
<%= f.text_area(:instructions, {class: "form-control"}) %>
<%= f.submit('Create Project') %>
<% end %>
在控制器中,我有两个动作:
def create
@project = Project.new( project_params )
if @project.save
flash[:notice]= "New project created!"
redirect_to(:action=>'index')
else
flash[:error]="Problem creating project"
redirect_to(:action=>'new')
end
end
def new
@project = Project.new()
end
我有几个验证可以防止字段为空。当表单失败时,我再次被重定向回“新”页面,但@project
变量始终为空。
为什么?