我是一个完全的 Rails 菜鸟,但一直在自学,我似乎能够自己解决简单的问题。但是,我目前有一个问题似乎无法解决。当我在填写表单上的所有字段后调用我的“新”或“创建”操作来创建新记录时,我得到空白记录被提交到数据库。所有字段均为“空”。
INSERT INTO `clients` (`accountholder`, `allergies`, `birthdate`, `cell`, `created_at`, `data1`, `data2`, `data3`, `data4`, `emailaddress`, `fax`, `middlename`, `name`, `surname`, `tel`, `text`, `updated_at`) VALUES (NULL, NULL, NULL, NULL, '2012-08-20 09:10:46', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '2012-08-20 09:10:46')
我可以在@post = Client.update_attributes(params[:id]) 中的控制台上看到日志转储期间的数据是正确的。
客户端控制器.rb
def new
@post = Client.create
end
def create
@post = Client.new(params[:posts])
if @post.save
redirect_to clients_path
else
render "new"
end
end
index.html.erb
<%= form_for @post do |x| %>
<p>
<%= x.label :name %><br />
<%= x.text_field :name, :cols => "30", :rows => "1" %>
</p>
<p>
<%= x.label :surname %>
<%= x.text_area :surname, :cols => "30", :rows => "1" %>
</p>
<p>
<%= x.label :middlename %>
<%= x.text_area :middlename, :cols => "30", :rows => "1" %>
</p>
<p>
<%= x.label :tel %>
<%= x.text_area :tel, :cols => "30", :rows => "1" %>
</p>
<p>
<%= x.label :cell %>
<%= x.text_area :cell, :cols => "30", :rows => "1" %>
</p>
<p>
<%= x.label :allergies %>
<%= x.text_area :allergies, :cols => "30", :rows => "10" %>
</p>
<p>
<%= x.label :fax %>
<%= x.text_area :fax, :cols => "30", :rows => "1" %>
</p>
<p>
<%= x.label :birthdate %>
<%= x.text_area :birthdate, :cols => "30", :rows => "1" %>
</p>
<p>
<%= x.submit "Add a New Client" %>
</p>
<% end %>
任何意见,将不胜感激。