在视图中(/employees/new.html.erb)
<%= form_for(@employee) do |f| %>
<%= f.label(:name, "Name of Employee") %>
<%= f.text_field(:name)%></br>
<%= f.label(:email, "Email id") %>
<%= f.text_field(:email) %></br>
<%= f.label(:password, "Password") %>
<%= f.text_field(:password) %></br>
<%= f.label(:city_id, "city") %>
<%= f.collection_select(:city_id, @city, :id, :city_name)%></br>
<%= f.label(:time_zone, "choose time zone") %>
<%= f.time_zone_select(:time_zone) %></br>
<%= f.label(:birth_date, "Date of Birth")%>
<%= f.date_select(:birth_date) %></br></br>
<%= f.submit "add employee" %>
<% end %>
在员工控制器中,
def new
@employee = Employee.new(:city_id => 11)
@city = City.all
end
def create
@employee = Employee.new(params[:employee])
@employee.save
redirect_to :action => :index
end
在员工模型中
class Employee < ActiveRecord::Base
attr_accessible :email, :name, :password, :city_id, :time_zone, :birth_date
belongs_to :city
end
但是,当我从浏览器提交表单时。我得到如下错误,
ActiveRecord::MultiparameterAssignmentErrors in EmployeesController#create
1 error(s) on assignment of multiparameter attributes
除了date_select表单助手之外,一切都很完美, 我认为, 我应该在应用程序的某个地方实现以下代码。
"Date.civil(params[:start_date][:year].to_i, params[:start_date][:month].to_i, params[:start_date][:day].to_i)"
请有人帮我解决此问题。 感谢