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