Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

undefined local variable or method `password' for #<User:0x007f8bb1791cd0> #53

Open
larryzhao opened this issue Sep 18, 2012 · 8 comments

Comments

@larryzhao
Copy link

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.

@nbudin
Copy link
Owner

nbudin commented Sep 18, 2012

Does your model include :validatable? If so, override the password_required? method to always return false.

@fabianoalmeida
Copy link

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.

@nbudin
Copy link
Owner

nbudin commented Aug 23, 2013

@fabianoalmeida Did you set cas_base_url in your Devise initializer?

@richardun
Copy link

@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?

@fabianoalmeida
Copy link

@nbudin yeah, I did it. 😔
@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!

@nbudin
Copy link
Owner

nbudin commented Aug 26, 2013

@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.

@fabianoalmeida
Copy link

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.

@zhyt1985
Copy link

zhyt1985 commented Jan 6, 2015

In your User Model add "include Devise::Models::DatabaseAuthenticatable"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants