for the life of me, i cannot get validates_presence_of to return any errors, leaving the form blank and clicking submit fails on the create or save method, but no validation errors are rendered. http://pastie.caboo.se/98101 --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
i should note that update_attributes is working On Sep 17, 4:29 pm, terry <jonathan.o...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> for the life of me, i cannot get validates_presence_of to return any > errors, leaving the form blank and clicking submit fails on the create > or save method, but no validation errors are rendered. > > http://pastie.caboo.se/98101--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 9/17/07, terry <jonathan.otto-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > for the life of me, i cannot get validates_presence_of to return any > errors, leaving the form blank and clicking submit fails on the create > or save method, but no validation errors are rendered. > > http://pastie.caboo.se/98101You''re getting confused as to how errors are reported. When you write <%= error_messages_for :job %> It looks for a model object in the instance variable @job (like how form_for works). The error messages are stored in the model object by a call to valid? (or save, create, etc.). But you don''t have an @job variable, so error_messages_for doesn''t find anything. Your controller code is wrong. First, create() will return a Job model object, even if it couldn''t be saved. So the "if" part is always true. Second, you are doing a redirect after the create. But if you had an error, your error messages would be lost due to the redirect. This should work: @job = current_user.jobs.build(params[:job]) if @job.save flash[:notice] = "job has been posted" redirect_to :action => ''index'' return end render :action => ''new'' Note the render instead of redirect at the end. If the save fails, you need @job to be passed to the view, because it contains the error messages. HTH --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
wow, awesome. thank you bob On Sep 17, 4:45 pm, "Bob Showalter" <showa...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 9/17/07, terry <jonathan.o...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > for the life of me, i cannot get validates_presence_of to return any > > errors, leaving the form blank and clicking submit fails on the create > > or save method, but no validation errors are rendered. > > >http://pastie.caboo.se/98101 > > You''re getting confused as to how errors are reported. > > When you write > > <%= error_messages_for :job %> > > It looks for a model object in the instance variable @job (like how > form_for works). The error messages are stored in the model object by > a call to valid? (or save, create, etc.). > > But you don''t have an @job variable, so error_messages_for doesn''t > find anything. > > Your controller code is wrong. First, create() will return a Job model > object, even if it couldn''t be saved. So the "if" part is always true. > > Second, you are doing a redirect after the create. But if you had an > error, your error messages would be lost due to the redirect. > > This should work: > > @job = current_user.jobs.build(params[:job]) > if @job.save > flash[:notice] = "job has been posted" > redirect_to :action => ''index'' > return > end > render :action => ''new'' > > Note the render instead of redirect at the end. If the save fails, you > need @job to be passed to the view, because it contains the error > messages. > > HTH--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---