# Error\_messages\_for help

**URL:** <https://www.ruby-forum.com/t/error-messages-for-help/174592>\
**Category:** Rails\
**Created:** [August 29, 2009, 10:53am UTC](https://www.ruby-forum.com/t/error-messages-for-help/174592 "2009-08-29T10:53:11Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![bgumbiker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/278dde/32.png) [@bgumbiker](https://www.ruby-forum.com/u/bgumbiker)\
**Post date:** [August 29, 2009, 10:53am UTC](https://www.ruby-forum.com/t/error-messages-for-help/174592/1 "2009-08-29T10:53:11Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bgumbiker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/278dde/32.png) [@bgumbiker](https://www.ruby-forum.com/u/bgumbiker)\
**Post date:** [August 29, 2009, 11:00am UTC](https://www.ruby-forum.com/t/error-messages-for-help/174592/2 "2009-08-29T11:00:42Z")

</div>

> 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

---

<div class="post-metadata">

**Author:** ![bgumbiker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/278dde/32.png) [@bgumbiker](https://www.ruby-forum.com/u/bgumbiker)\
**Post date:** [August 30, 2009, 5:31am UTC](https://www.ruby-forum.com/t/error-messages-for-help/174592/3 "2009-08-30T05:31:11Z")

</div>

On Aug 29, 7:00 pm, Rails L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> ## \<%= error\_messages\_for ‘quotation’ %\> just after the remote\_form\_for tag
> 
> Posted viahttp://www.ruby-forum.com/.

No success. Any other ideas?  
thanks

---

<div class="post-metadata">

**Author:** ![bgumbiker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/278dde/32.png) [@bgumbiker](https://www.ruby-forum.com/u/bgumbiker)\
**Post date:** [August 30, 2009, 9:53am UTC](https://www.ruby-forum.com/t/error-messages-for-help/174592/4 "2009-08-30T09:53:25Z")

</div>

2009/8/29 bgumbiker [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> “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

---

<div class="post-metadata">

**Author:** ![bgumbiker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/278dde/32.png) [@bgumbiker](https://www.ruby-forum.com/u/bgumbiker)\
**Post date:** [August 31, 2009, 7:14am UTC](https://www.ruby-forum.com/t/error-messages-for-help/174592/5 "2009-08-31T07:14:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bgumbiker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/278dde/32.png) [@bgumbiker](https://www.ruby-forum.com/u/bgumbiker)\
**Post date:** [August 31, 2009, 12:37pm UTC](https://www.ruby-forum.com/t/error-messages-for-help/174592/6 "2009-08-31T12:37:22Z")

</div>

On Aug 30, 4:29 am, bgumbiker [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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

---

<div class="post-metadata">

**Author:** ![bgumbiker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/278dde/32.png) [@bgumbiker](https://www.ruby-forum.com/u/bgumbiker)\
**Post date:** [September 4, 2009, 3:18am UTC](https://www.ruby-forum.com/t/error-messages-for-help/174592/7 "2009-09-04T03:18:17Z")

</div>

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

On Aug 31, 8:21 pm, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![bgumbiker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/278dde/32.png) [@bgumbiker](https://www.ruby-forum.com/u/bgumbiker)\
**Post date:** [September 4, 2009, 8:00pm UTC](https://www.ruby-forum.com/t/error-messages-for-help/174592/8 "2009-09-04T20:00:35Z")

</div>

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.
