我有一组简单的是或否单选按钮与 :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