【发布时间】:2015-06-04 18:02:23
【问题描述】:
在运行带有带有 formtastic 支持的nested_form gem 的 Rails 3.2.11 时,当出现错误时,选择字段下方的 f.select 助手不会显示验证错误消息。
如果我将 f.select 更改为 f.input,则会在字段下方显示错误。这是一个错误还是 Rails 不会自动为选择字段的验证注入错误?
我基本上通过利用 Rails 提供的“Model”.errors.messages 助手来修复它,但它会导致一些我想避免的自定义 if/else 逻辑。如果可能的话,我宁愿让 Rails 自动注入 *<p class="inline-errors">some error message</p>*。
model.rb
validates :consultant, :presence => { :message => "consultant is missing." }
form.html.haml
= semantic_nested_form_for @agreement, :url => "/agreements/update", :html => { :class => "agreement", :autocomplete => "off" } do |f|
= f.select :consultant, options_for_select(["","option1","option2"], @service_agreement.assigned_consultant)
【问题讨论】: