Milton Wong
2008-Aug-29 15:32 UTC
Validation doesn''t work (ActiveRecord::BaseWithoutTable)
Hi,
I understand that the active_record_base_without_table is supposed to be
an easy install. So I am not sure why the validation doesn''t work out
of
the box (base_without_table.rb attached). No valdn error msgs and it
takes all values.
Am I missing any steps?
I am creating a change password page where it compares old_password with
the stored password in the database. And then user can change it.
View simply has :old_password, :new_password, and
:new_password_confirmation
The Password controller:
------------------------
class PasswordsController < ApplicationController
layout ''base''
before_filter :load_user
before_filter :check_auth
def new
@password = Password.new
respond_to do |format|
format.html #new.html.erb
end
end
def change
puts params
if !params[:password][:old_password].blank? or
!params[:password][:new_password].blank?
@old_password = params[:password][:old_password]
@new_password = params[:password][:new_password]
@encrypted_original = @user.encrypted_password
if !@user.compare_password(@encrypted_original, @old_password)
flash[:notice] = ''Sorry, we could not find your old password in
our database. Please enter the old password again''
else
@user.encrypted_password Standards.encrypt_a_code(@new_password)
@user.save(perform_validations=false)
flash[:notice] = ''Your new password has been saved''
end
end
redirect_to :action => ''new''
end
end
The Password model:
-------------------
class Password < ActiveRecord::BaseWithoutTable
column :old_password, :string
column :new_password, :string
validates_presence_of :old_password
attr_accessor :old_password, :new_password, :new_password_confirmation
validates_confirmation_of :new_password, :message => "New password
should match confirmation"
validates_length_of :old_password, :new_password, :minimum => 6
end
Attachments:
http://www.ruby-forum.com/attachment/2630/base_without_table.rb
--
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?hl=en
-~----------~----~----~----~------~----~------~--~---
David Rose
2008-Aug-29 15:49 UTC
Re: Validation doesn''t work (ActiveRecord::BaseWithoutTable)
The validations will be run when you call .save on your instance of Password: @password.save David Rose On Fri, Aug 29, 2008 at 10:32 AM, Milton Wong < rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Hi, > > I understand that the active_record_base_without_table is supposed to be > an easy install. So I am not sure why the validation doesn''t work out of > the box (base_without_table.rb attached). No valdn error msgs and it > takes all values. > Am I missing any steps? > > I am creating a change password page where it compares old_password with > the stored password in the database. And then user can change it. > > View simply has :old_password, :new_password, and > :new_password_confirmation > > The Password controller: > ------------------------ > class PasswordsController < ApplicationController > > layout ''base'' > > before_filter :load_user > before_filter :check_auth > > def new > @password = Password.new > > respond_to do |format| > format.html #new.html.erb > end > end > > def change > puts params > if !params[:password][:old_password].blank? or > !params[:password][:new_password].blank? > @old_password = params[:password][:old_password] > @new_password = params[:password][:new_password] > @encrypted_original = @user.encrypted_password > if !@user.compare_password(@encrypted_original, @old_password) > flash[:notice] = ''Sorry, we could not find your old password in > our database. Please enter the old password again'' > else > @user.encrypted_password > Standards.encrypt_a_code(@new_password) > @user.save(perform_validations=false) > flash[:notice] = ''Your new password has been saved'' > end > end > redirect_to :action => ''new'' > end > end > > > The Password model: > ------------------- > class Password < ActiveRecord::BaseWithoutTable > column :old_password, :string > column :new_password, :string > > validates_presence_of :old_password > > attr_accessor :old_password, :new_password, :new_password_confirmation > > validates_confirmation_of :new_password, :message => "New password > should match confirmation" > validates_length_of :old_password, :new_password, :minimum => 6 > > end > > Attachments: > http://www.ruby-forum.com/attachment/2630/base_without_table.rb > > -- > 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?hl=en -~----------~----~----~----~------~----~------~--~---