Hello,
Does anyone know how to use error_messages_for with remote_form_for?
Here is my code:
<%= error_messages_for ‘quotation’ %>
<% 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
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 placing
<%= error_messages_for ‘quotation’ %> just after the remote_form_for
tag
On Aug 29, 7:00 pm, Rails L. [email protected]
wrote:
<%= error_messages_for ‘quotation’ %> just after the remote_form_for
tag
Posted viahttp://www.ruby-forum.com/.
No success. Any other ideas?
thanks
2009/8/29 bgumbiker [email protected]:
“send_quotation” }) do |f| %>
the controller?
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 L. 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
On Aug 30, 4:29 am, bgumbiker [email protected] wrote:
No success. Any other ideas?
thanks
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
On Aug 31, 8:21 pm, Frederick C. [email protected]
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 J.