2012-01-04 40 views
1

我在使用Rails的日期幫手表單提交失敗多於一個date_select幫手的Rails 3

date_select

麻煩,如果我只有一個形式,然後形式完美地提交到數據庫,但如果另我date_select幫手標記添加到我的形式,然後我收到以下錯誤:

ActiveRecord::MultiparameterAssignmentErrors in Admin::StudentRegistrationsController#create

1 error(s) on assignment of multiparameter attributes

我的控制器是通常的支架之一:

# POST /student_registrations 
# POST /student_registrations.xml 
def create 
@student_registration = StudentRegistration.new(params[:student_registration]) 
respond_to do |format| 
if @student_registration.save 
format.html { redirect_to(@student_registration, :notice => 'Student registration was successfully created.') } 
format.xml { render :xml => @student_registration, :status => :created, :location => @student_registration } 
else 
format.html { render :action => "new" } 
format.xml { render :xml => @student_registration.errors, :status => :unprocessable_entity } 
end 
end 
end 

,我的看法如下:

<%= form_for([:admin, @student_registration]) do |f| %> 
<div class="reg_title"> 
Date of Birth 
</div> 
<div class="reg_content"> 
<%= f.date_select(:DOB,:start_year => 1940) %> 
</div> 
<div class="reg_title"> 
Passport Expiry Date 
</div> 
<div class="reg_content"> 
<%= f.date_select(:PPortE,:start_year => 1940) %> 
</div> 
<div class="actions"> 
<%= f.submit %> 
</div> 
<% end %> 

在我的PARAMS日期走到一起,所以沒有空白:

"DOB(1i)"=>"1979", "DOB(2i)"=>"9", "DOB(3i)"=>"4", "PPortE(1i)"=>"2012", "PPortE(2i)"=>"1", "PPortE(3i)"=>"4"},

但是,如果我再次註釋掉護照EXP date_select休息的表格將提交。任何想法,將不勝感激

回答

4

解決。問題是數據庫中passport exp date的數據類型,由於某種原因,它被設置爲VARCHAR而不是DATE。我想,使用遺留數據庫的結果!

+0

今天我有同樣的問題。我注意到這個問題促使我看看我的遷移 - 我把date_of_birth作爲一個:字符串而不是:date。感謝您解決您自己的查詢! – LpLrich 2013-11-20 14:22:51