# Validates\_presence\_of

**URL:** <https://www.ruby-forum.com/t/validates-presence-of/136901>\
**Category:** Rails\
**Created:** [May 7, 2008, 8:20am UTC](https://www.ruby-forum.com/t/validates-presence-of/136901 "2008-05-07T08:20:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![sijo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@sijo](https://www.ruby-forum.com/u/sijo)\
**Post date:** [May 7, 2008, 8:20am UTC](https://www.ruby-forum.com/t/validates-presence-of/136901/1 "2008-05-07T08:20:58Z")

</div>

Hi  
I have a model class SDResolution.It has fields code and solution.I  
have to make the solution not empty .So for that I wrote  
validates\_presence\_of :resolution in the model.So from the view when  
I click save nothing is saved to database.This is what I need.But no  
error messages are printed and the view goes to next window…How can I  
print error messages in the current window?

Thanks in advance  
Sijo

---

<div class="post-metadata">

**Author:** ![sijo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@sijo](https://www.ruby-forum.com/u/sijo)\
**Post date:** [May 7, 2008, 10:29am UTC](https://www.ruby-forum.com/t/validates-presence-of/136901/2 "2008-05-07T10:29:15Z")

</div>

that’s a question of your controller logic.

do it something like that:

def update  
@sdresolution = SDResolution.find(params[:id]  
if @sdresolution.update\_attributes(params[:sdresolution]) then  
…render next view—  
else  
redirect\_to edit action (or just render edit view again)  
end  
end

in your view (for edit) just add  
\<%= error\_messages\_for(:SDResolution) %\>  
this will display error messages if there are any on the @sdresolution  
object

---

<div class="post-metadata">

**Author:** ![sijo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@sijo](https://www.ruby-forum.com/u/sijo)\
**Post date:** [May 7, 2008, 11:47am UTC](https://www.ruby-forum.com/t/validates-presence-of/136901/3 "2008-05-07T11:47:27Z")

</div>

had a very short look at it (sorry, have some work to do)

but it seems in your action you do:  
@update\_sd\_ticket\_resolution=@sd\_ticket\_resolution.update\_attributes(params[:sd\_resolution])

using @sd\_ticket\_resolution

while your view uses:  
\<%= error\_messages\_for ‘service\_desk\_resolution’ %\>

this should be  
\<%= error\_messages\_for ‘sd\_ticket\_resolution’ %\>

to render the errors that may be on @sd\_ticket\_resolution  
after the update\_attributes

---

<div class="post-metadata">

**Author:** ![sijo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@sijo](https://www.ruby-forum.com/u/sijo)\
**Post date:** [May 7, 2008, 11:34am UTC](https://www.ruby-forum.com/t/validates-presence-of/136901/4 "2008-05-07T11:34:05Z")

</div>

Hi  
I am using ajax submit to remote here…I could succeed this  
validation on another place without ajax…I am attaching the code for  
this .Could you please go through it and make a suggestion?

Thanks  
Sijo

---

<div class="post-metadata">

**Author:** ![sijo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@sijo](https://www.ruby-forum.com/u/sijo)\
**Post date:** [May 7, 2008, 12:54pm UTC](https://www.ruby-forum.com/t/validates-presence-of/136901/5 "2008-05-07T12:54:43Z")

</div>

Hi  
Thanks for your reply…Stil have problem .Could you please look at the  
code when get time?

Thanks in advance  
Sijo
