#149 √ invalid
Glenn Rempe

Form helper #error_messages_for does not work with ActiveRecord

Reported by Glenn Rempe | August 23rd, 2008 @ 06:19 AM | in 0.9.5

It appears that #error_messages_for does not support AR model errors.

AR returns and ActiveRecord::Errors object which contains an @error instance variable with an error hash in it.

This type of response is not tested in the specs.

Here is the IRC chat session as a reminder.


[7:39pm] grempe: Hi all.  I noticed that the form helpers in merb-plugins are undergoing significant refactoring.  Is it a known issue that error_messages_for no longer seems to work for ActiveRecord?  Or shall I file a bug?
[7:40pm] hassox: GMFlash: ^^
[7:40pm] bryanray: grempe: what is the error you're seeing?
[7:40pm] GMFlash: grempe:  can you post a stack trace?
[7:41pm] GMFlash: and also a snippet of your view
[7:41pm] grempe: There is no stack trace.  I just sends back nothing...  and as far as I can tell, the spec's don't reflect what an AR model looks like...
[7:41pm] GMFlash: are you using <%= error_messages_for ... %> ?
[7:43pm] grempe: yes.  here is a sample AR model error that I grabbed from 'merb -i' session :  http://pastie.org/258422
[7:44pm] grempe: and here is how I am calling it:  = error_messages_for @publisher
[7:44pm] grempe: the specs for calling it with a symbol are commented out now.  so I don't know if that works...
[7:44pm] grempe: and the specs seem to indicate testing with an 'AR-like' model but actually reference what appears to be the datamapper example
[7:45pm] grempe: line 8 in merb_helpers_form_spec.rb
[7:45pm] GMFlash: as long as @publisher has a .errors method and it isn't empty it should work
[7:46pm] grempe: Here is my edit view:  http://pastie.org/258424
[7:50pm] grempe: GMFlash : could it be that the method is expecting a simple array to be returned, but active record actually returns an ActiveRecord::Errors object?
[7:51pm] GMFlash: as long as the AR:Errors object responds to .each it will work
[7:57pm] grempe: GMFlash : the specs are testing for an array with :    @dm_errors = [["foo", "bar"],["baz","bat"]], but ActiveRecord returns a hash like : @errors={"name"=>["can't be blank"], "url"=>["can't be blank"]}
[7:59pm] grempe: Its here:  http://github.com/wycats/merb-plugins/tree/master/merb_helpers/spec/merb_helpers_form_spec.rb#L14
[7:59pm] grempe: All of this has changed in the last few days.  So just making sure that we all know what used to work no longer does...
[7:59pm] GMFlash: grempe: do you get any output such as a div or an empty <ul>?
[8:00pm] grempe: no.  nada.  zip
[8:00pm] GMFlash: nothing changed with #error_messages_for
[8:00pm] GMFlash: if you were using #error_messages_for from HEAD a few days ago then it should still function the same today
[8:07pm] grempe: GMFlash : are you the developer of the most recent changes?
[8:08pm] GMFlash: mostly wycats is with some help from myself and bryanray
[8:08pm] grempe: I am digging through the changesets to see if I notice something that changed.  I was not using error_messages_for a few days ago.  All I know is it don't work
[8:09pm] grempe: I sent you my view.  Am I using it incorrectly?  I don't think so...
[8:09pm] GMFlash: error_messages_for was refactored but it was a couple months ago. chances are it might not be compatible with activerecord's error hash
[8:09pm] GMFlash: i'll make sure it gets tested
[8:10pm] GMFlash: 0.9.5 should be coming out this weekend and we want to get the helpers in
[8:10pm] GMFlash: so activerecord support will definitely be working
[8:10pm] grempe: And I notices in the comments : "# @todo - error_messages_for needs more complete specs"
[8:11pm] grempe: ok.  awesome.
[8:11pm] grempe: Need me to file a bug?

Comments and changes to this ticket

Please Login or create a free account to add a new comment.

You can update this ticket by sending an email to from your email client. (help)

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Shared Ticket Bins

People watching this ticket