Validates_presence_of

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

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

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

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

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

Thanks in advance
Sijo