我擁有簡單的yes或no單選按鈕:needs_dist。當我提交沒有選擇的表單時,它工作得很好,但是當我選擇了Yes時,它會拋出一個驗證錯誤?它僅在以下情況下進行驗證:needs_dist => true。Rails 4單選按鈕表單助手,真正不驗證
型號
validates_presence_of :contact_name, :email, :postal_code, :series_id, :product_id, :company_name, :needs_dist
查看
<%= f.radio_button(:needs_dist, "false") %>
<%= f.label :needs_dist, "Yes" %>
<%= f.radio_button(:needs_dist, "true") %>
<%= f.label :needs_dist, "No" %>
控制器(以防萬一)
def create_quote
@quote_request = QuoteRequest.new safe_quote_params
if @quote_request.save
@email = SiteMailer.quote_request(@quote_request).deliver
render :template => "request/quote_sent"
else
@series = Series.find params[:quote_request][:series_id] unless params[:quote_request][:series_id].blank?
render :template => "request/quote.html"
end
end
這工作完美,謝謝! –