Hey All, I''m frustrated with validates_presence_of. I have a form, and I''m validating four fields using validates_presence_of.. It works fine, except that when the form comes back with the error messages, it is blank. If a user enters three of the four required fields and submits the form, they get back a blank form with an error message and have to re-enter everything. It seems to me like there must be an easy way to fix this, otherwise v_p_o is a total joke. I''ve googled my head off to no good effect. Can anyone offer advice? Thanks, JB --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
One way to make this happen is to do a redirect in the controller after Model.save or Model.update_attributes rather than a render back to the new or edit action. Could that be your problem? (If that''s not clear, post the update method of the appropriate controller.) HTH, -Roy -----Original Message----- From: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org [mailto:rubyonrails-talk@googlegroups.com] On Behalf Of justinbankston Sent: Thursday, October 09, 2008 11:25 AM To: Ruby on Rails: Talk Subject: [Rails] validates_presence_of and a blank form... Hey All, I''m frustrated with validates_presence_of. I have a form, and I''m validating four fields using validates_presence_of.. It works fine, except that when the form comes back with the error messages, it is blank. If a user enters three of the four required fields and submits the form, they get back a blank form with an error message and have to re-enter everything. It seems to me like there must be an easy way to fix this, otherwise v_p_o is a total joke. I''ve googled my head off to no good effect. Can anyone offer advice? Thanks, JB --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
To add to the previous post...make sure that you label you form
correctly, for example:
<% form_for(@person) do |f| %>
<%= f.error_messages %>
<p>
<%= f.label :name%><br />
<%= f.text_field :name %>
</p>
<p>
<%= f.submit "Create" %>
</p>
<% end %>
in the code above, if the @person has a name, the text_field is then
populated with that value. or what you could do is get the choice made
by the user i.e.: <% selected_choice
@survey.get_choice_for_question(@question) %>
end if it''s not nil display it as follows: <% selected_choice_id
selected_choice.id unless selected_choice.nil? %>
(i have a random number of questions so i use a loop to display each
one and get the appropriate answers and such so you have to adapt my
code to what you have)
I had the same problem and this fixed it for me, so i hope it helps.
if not, show us your code and we''ll see how we can help.
On Oct 9, 3:07 pm, "Pardee, Roy"
<parde...-go57ItdSaco@public.gmane.org> wrote:> One way to make this happen is to do a redirect in the controller after
Model.save or Model.update_attributes rather than a render back to the new or
edit action. Could that be your problem?
>
> (If that''s not clear, post the update method of the appropriate
controller.)
>
> HTH,
>
> -Roy
>
> -----Original Message-----
> From: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
[mailto:rubyonrails-talk@googlegroups.com] On Behalf Of justinbankston
> Sent: Thursday, October 09, 2008 11:25 AM
> To: Ruby on Rails: Talk
> Subject: [Rails]validates_presence_ofand ablankform...
>
> Hey All,
>
> I''m frustrated withvalidates_presence_of. I have aform, and
I''m validating four fields usingvalidates_presence_of..
>
> It works fine, except that when theformcomes back with the error messages,
it isblank. If a user enters three of the four required fields and submits
theform, they get back ablankformwith an error message and have to re-enter
everything.
>
> It seems to me like there must be an easy way to fix this, otherwise v_p_o
is a total joke.
>
> I''ve googled my head off to no good effect. Can anyone offer
advice?
>
> Thanks,
> JB
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---