justinfrench/formtastic — Issue #759: semantic_errors doesn't return errors on base object
Author: trevrosen
Created: 2011-12-16 19:42:37+00:00
State: open

Hard to believe, but seems to be true. I've fixed the issue in a fork, and would appreciate any feedback I can get. I've been looking for a flaw in my repro process or my understanding of the code because it makes no sense to me this core functionality would be broken in such a widely used library. If this is a reasonable fix, I'll spec it up and create a proper pull request.

https://github.com/trevrosen/formtastic/commit/2fddba5c6137a35426764be843a14ec3fe6a5c9b

The issue seems to be that you're referencing the old errors API. As far as I can tell, the following always returns nil in the semantic_errors method body:

```ruby
@object.errors[:base]
```

__Repro:__

* Create new Rails app with Rails 3.1.3 and "gem 'formtastic'" in the Gemfile
* Add scaffolding/schema for User model, including string attribute __name__
* add "validates_presence_of :name" to models/user.rb
* Replace _form.html.erb code w/ Formtastic code
* Include a call to semantic_errors at the top of form block
* Attempt to create the user with a blank name

Inline errors will show, unordered list of errors will not. Using the debugger, you can see that

```ruby
@object.errors[:base] #=> nil
@object.errors.keys #=> [:name]
```