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
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
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 etc
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 etc
Validations 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
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.