L
laredotornado
Hi, When validating a field in my user model, I wrote a method
"is_client?" to help with the validation. But I did it wrong because
now I'm getting this error:
NoMethodError in SessionController#create
undefined method `is_client?' for User:Class
RAILS_ROOT: ./script/../config/..
Application Trace | Framework Trace | Full Trace
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.5/lib/
active_record/base.rb:1238:in `method_missing'
/usr/local/apache2/htdocs/easyrx/app/models/user.rb:16
/usr/local/apache2/htdocs/easyrx/app/controllers/session_controller.rb:
12:in `create'
Here's the relevant code. Any ideas what I can do to get rid of this
error? Thanks, - Dave
class User < ActiveRecord::Base
...
validates_as_phone :work_phone, :if => !:work_phone.blank? &&
is_client?, :message => "is not a valid phone number" # line
16
attr_accessible :user_type_id, :user_group_id,
harmacy_id,
hone, :work_phone, :work_phone_extension, :fax, :bill_to_first_name, :bill_to_last_name, :bill_to_street, :bill_to_city, :bill_to_state, :bill_to_zip, :bill_to_country, :ship_to_first_name, :ship_to_last_name, :ship_to_street, :ship_to_city, :ship_to_state, :ship_to_zip, :ship_to_country, :bill_to_attn, :ship_to_attn, :bill_to_company, :ship_to_company, :bill_to_street2, :ship_to_street2, :login, :email,
assword,
assword_confirmation
....
def is_client?
user_type_id == 2
end
end
"is_client?" to help with the validation. But I did it wrong because
now I'm getting this error:
NoMethodError in SessionController#create
undefined method `is_client?' for User:Class
RAILS_ROOT: ./script/../config/..
Application Trace | Framework Trace | Full Trace
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.5/lib/
active_record/base.rb:1238:in `method_missing'
/usr/local/apache2/htdocs/easyrx/app/models/user.rb:16
/usr/local/apache2/htdocs/easyrx/app/controllers/session_controller.rb:
12:in `create'
Here's the relevant code. Any ideas what I can do to get rid of this
error? Thanks, - Dave
class User < ActiveRecord::Base
...
validates_as_phone :work_phone, :if => !:work_phone.blank? &&
is_client?, :message => "is not a valid phone number" # line
16
attr_accessible :user_type_id, :user_group_id,
....
def is_client?
user_type_id == 2
end
end