我有简单的是或否单选按钮附加到:needs_dist。当我提交没有选择的表单时,它工作得很好,但是当我选择了是时,它会抛出一个验证错误?它仅在 :needs_dist => true 时验证。
模型
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