Hi its a really simple thing but i can''t get validation to kick in on updates. It lets me put in any junk instead of a valid email and saves it. I have tried :on => :update :on => :save if @user.save if @user.update with the same results. can anyone see what my problem is? regards Clare def update_email @user = Subscriber.find_by_id(session[:user]) @user.email = params[:new_email] if @user.save redirect_to :action => ''index'' else render :action => ''change_email'' end end validates_format_of :email,:with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i, :on => :save -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> :on => :update > :on => :save> if @user.update> def update_email > @user = Subscriber.find_by_id(session[:user]) > @user.email = params[:new_email] > if @user.save > redirect_to :action => ''index'' > else > render :action => ''change_email'' > end > endwhere''s the update method in your controller? maybe (guessing longshot) putting :on => :update_email will work? or using the update method in the given action etc ? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
That was just one variation f my update method, the other one is identical apart from the line "if @user.save" is replaced with "if @user.update". :on => :update_email == a horrible error regards c -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Stephen Bartholomew
2006-Sep-03 11:14 UTC
Re: simple validation silently fails on update or save
> where''s the update method in your controller? maybe (guessing longshot) > putting :on => :update_email > will work? or using the update method in the given action etcValidations are called against models, not controllers. Clare: You should be about to just leave set up the validation like this: class User < ActiveRecord::Base validates_format_of :email, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i end That should fire on any save command. Steve --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---