我在rails中使用简单的形式。提交数据后。页面总是返回application_form#new,数据无法保存在db中。为什么?
日志
Started POST "/application_forms" for 127.0.0.1 at 2013-05-25 19:23:28 +0800
Processing by ApplicationFormsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"yypWFcsXbdSVtp3WXUZKvstzHWsV0OOpLoGSxO1ldJ0=", "application_form"=>{"student_name"=>"somebody", ...... ,"application_type"=>"b"}, "commit"=>"Submit"}
[1m[35mUser Load (0.0ms)[0m SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
[1m[35m (0.0ms)[0m rollback transaction
Rendered application_forms/_form.html.erb (24.0ms)
Rendered application_forms/new.html.erb within layouts/application (25.0ms)
Completed 200 OK in 61ms (Views: 52.0ms | ActiveRecord: 0.0ms)
看法
<%= simple_form_for @application_form, :html => {:class => 'form-horizontal' } do |f| %>
<legend>Basic Info</legend>
<%= f.input :student_name %>
<%= f.button :submit, 'Submit', :class => 'btn-large btn-primary'%>
<% end %>
控制器
def create
@application_form = ApplicationForm.new(params[:application_form])
respond_to do |format|
if @application_form.save
format.html { redirect_to @application_form, :notice => 'Submit ok.' }
else
format.html { render :action => "new" }
end
end
end