devise_cas_authenticatable
devise_cas_authenticatable copied to clipboard
undefined local variable or method `password' for #<User:0x007f8bb1791cd0>
After I logged in successfully against rubycas-server
, I got this error:
Started GET "/users/sign_in" for 127.0.0.1 at 2012-09-18 23:48:03 +0800
Processing by Devise::CasSessionsController#new as HTML
Redirected to http://cas.mydomain.com/login?service=http%3A%2F%2F127.0.0.1%3A3000%2Fusers%2Fservice
Completed 302 Found in 0ms (ActiveRecord: 0.0ms)
Started GET "/users/service?ticket=ST-1347983282r2B9C399B1EF21A07C2" for 127.0.0.1 at 2012-09-18 23:48:03 +0800
Processing by Devise::CasSessionsController#service as HTML
Parameters: {"ticket"=>"ST-1347983282r2B9C399B1EF21A07C2"}
User Load (0.4ms) SELECT `users`.* FROM `users` WHERE `users`.`username` = 'renli' LIMIT 1
(0.1ms) BEGIN
(0.1ms) ROLLBACK
Completed 500 Internal Server Error in 874ms
NameError (undefined local variable or method `password' for #<User:0x007f8bb1791cd0>):
activemodel (3.2.8) lib/active_model/attribute_methods.rb:407:in `method_missing'
activerecord (3.2.8) lib/active_record/attribute_methods.rb:149:in `method_missing'
devise (2.1.2) lib/devise/models/validatable.rb:54:in `password_required?'
activesupport (3.2.8) lib/active_support/callbacks.rb:436:in `_run__3925759518155993811__validate__1547609540827105941__callbacks'
activesupport (3.2.8) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.8) lib/active_support/callbacks.rb:385:in `_run_validate_callbacks'
And if I add attr_accessor :password
then everything looks OK. But actually since we are authenticating against the CAS system. It's unnecessary to have the password
field.
Does your model include :validatable? If so, override the password_required? method to always return false.
Hi @larryzhao. I'm having problems with to use this gem logging in a rubycas-server
. Could you show me how did you do your app configuration?
I'm not getting call rubycas-server
login page. I configured devise :cas_authenticatable
on User model, created username
column on users
table, but I don't know how to configure my routes.rb
to redirect to my rubycas-server
login page.
If you @nbudin know answering my doubts, please, show me. Thanks in advance!
Update
I'm using rails 4
.
@fabianoalmeida Did you set cas_base_url
in your Devise initializer?
@fabianoalmeida, you'll also want to make sure you are making controllers check authentication in a before_filter. Obviously, this is more on the devise side of the configuration, but it's a possibility for what you're seeing. I usually put mine in the application_controller.rb:
before_filter :authenticate_user!, :unless => :devise_controller?
@nbudin yeah, I did it. :pensive: @richardun I also did it, but it's not working. Do you suggest another tip to solve it?
I have a silly question... Using this gem I need create a User table, right? Could I ignore it? I mean... Is this really necessary (create User table on database)?
Thanks in advance!
@fabianoalmeida Yes, you do need a User table, because Devise requires one by design. I can see why you might say it wouldn't be necessary, but for Devise, it is.
If you want to avoid having a User table, I suggest looking into using rubycas-client directly rather than using this gem.
Thanks @nbudin! Yeah, you're right. I don't need a User table and I'm not getting put to work this gem with my app. After searching a little more I found this gem: rack-cas. It's simple, few configurations and doesn't need to create a useless table.
Thank you so much for your time and help @nbudin.
In your User Model add "include Devise::Models::DatabaseAuthenticatable"