def create
item = current_administrator.items.build(params[:category1])
item.created_at = Time.now
item.save!
redirect_to root_path
end
代码不会item.save!
,因为它认为表单中的类别是空白的,但它们已经完成。
Validation failed: Item can't be blank, Category4 can't be blank, Category1 can't be blank
表格:
<%= form_for VerbRegular.new do |f| %>
<div id="add_verb_container">
<%= f.text_field :category1 %>
<%= f.text_field :category2 %>
<%= f.text_field :category3 %>
<%= f.check_box :type %>
<%= f.text_field :category4 %>
<%= f.text_field :comment %>
</div>
<%= f.submit "Add to list" %>
<% end %>
答案 0 :(得分:0)
build(params[:category1])?
只是传递 category1 ?可能你需要更像build(params[:verb_regular])