Frage

Unable to display validation errors using the gem 'bootstrap_forms', '~> 2.0.0' (http://github.com/potenza/bootstrap_form).

models/client.rb

class Client < ActiveRecord::Base
  attr_accessible :name
  validates :name, :presence => true
end

views/clients/new.html.haml

= bootstrap_form_for @client do |f|
  = f.object.errors.messages
  %h1 Create New Client
  .row-fluid
    .span3= f.text_field :name, :class => 'span50'
  = f.submit

When submitting the above form code, f.object.class is 'Client', and f.object.messages is an empty hash.

Switching this code to use rails built in form builder allows me to see the validation errors:

views/clients/new.html.haml

= form_for @client do |f|
  = f.object.errors.messages
  %h1 Create New Client
  .row-fluid
    .span3= f.text_field :name, :class => 'span50'
  = f.submit

Using this, f.object.messages is {:name=>["can't be blank"]}.

Does this make any sense? I cannot understand why f.object.errors.messages is empty.

War es hilfreich?

Lösung

Try this:

  f.errors.full_messages
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top