error_messages_for help

Hello, Does anyone know how to use error_messages_for with remote_form_for?

Here is my code:

<%= error_messages_for 'quotation' %>

<div id="quotation_form"> <% remote_form_for(Quotation.new, :url => { :action => "send_quotation" }) do |f| %> .... .... .... <% end %>

The <%= error_messages_for 'quotation' %> is always replaced by empty space in html as 'quotation' at that time is nil.

Any idea how to make it work without setting 'quotation' variable in the controller?

thanks, bogumbiker

No success. Any other ideas? thanks

I am a bit of a loss to understand what you are doing here, though this may be my problem rather than yours. As I understand it error_messages_for is displays the errors associated with the given variable. If quotation is nil how can it have errors associated with it? You have not described what you are doing to generate some errors that you would like to display. Presumably this is as a result of submitting the form that is being generated, if so what are you doing to get the invalid object back to the displayed page so its errors can be displayed?

Colin

Rails List wrote:

The <%= error_messages_for 'quotation' %> is always replaced by empty space in html as 'quotation' at that time is nil.

Any idea how to make it work without setting 'quotation' variable in the controller?

thanks, bogumbiker

Try this <%= error_messages_for "quotation", :object_name => "quotation" %>

After the remote_form_for tag

You need to write some javascript/rjs to (after form submission) render a partial (which displays errors in whatever way you want) and insert that into the appropriate part of the DOM

Fred

Thanks for all suggestion. It seems that the only solution is the javascript. bogumbiker

If you're returning RJS or the like from the AJAX call, the method I'd use would be to wrap the error_messages_for in a div and send back a page.replace call that fills it out. I've used this in a couple production apps without problems.

--Matt Jones