I also had the same problem. I tried adding a new file called form_builder.rb to the config / initializers folder of my project, and now it works fine.
Below is some content of my solution. base_helper.rb
def field_container(model, method, options = {}, &block)
css_classes = options[:class].to_a
if error_message_on(model, method).present?
css_classes << 'withError'
end
content_tag('p', capture(&block), :class => css_classes.join(' '), :id => "#{model}_#{method}_field")
end
form_builder.rb
class ActionView::Helpers::FormBuilder
def field_container(method, options = {}, &block)
@template.field_container(@object_name,method,options,&block)
end
def error_message_on(method, options = {})
@template.error_message_on(@object_name, method, objectify_options(options))
end
end
ActionView::Base.field_error_proc = Proc.new{ |html_tag, instance| "<span class=\"field_with_errors\">#{html_tag}</span>".html_safe }
_form.html.erb
<%= f.field_container :name do %>
<%= f.label :name, t("name") %> <span class="required">*</span><br />
<%= f.text_field :name %>
<%= f.error_message_on :name %>
<% end %>
source
share