NameError in Devise/registrationsController#create - ruby-on-rails-3

Im trying to use the gem Devise for a admin authentication. Ive used it before when I only wanted a user login but now I would like to have just a admin login. I followed the railscast for it and instead of naming the model User I gave it the name Admin. Everything worked fine until I tried to login then I got this error message:
uninitialized constant Devise::Encryptors::Bcrypt
I cant seem to find the problem. I have compared the code in the project with the other one I did and there is no difference. Is the problem due to the fact that I´m using Admin the wrong way?! Should I not use it as you would with a user?! Thankful for all help.
Regards

That encryption method appears to have been removed from Devise.
See: https://github.com/plataformatec/devise/issues/issue/527

Related

How to create a custom middleware while using rails 5 in api-mode?

I'm trying to create a custom middleware in rails 5 in api-mode where for only routes that don't start with /api/... it will add back in
middleware.use ActionDispatch::Cookies
middleware.use ActionDispatch::Cookies::Session
This post shows how to do it in rails 4:
OmniAuth::NoSessionError - You must provide a session to use OmniAuth. (configured in devise)
I'm trying to create a middleware like the accepted answer in the above post but when adding the
config.middleware.insert_before ActionDispatch::ParamsParser, "SelectiveStack"
to application.rb it throws an error saying it can't find SelectiveStack.
It also won't let me add a require or includes in the application.rb to access it, so I was wondering if anyone come across this or had any ideas?
I may just have the format wrong or have it in the wrong path.
It turns out that ActionDispatch::ParamsParser from the other stackoverflow post middleware doesn't actually exist and the wording of the error was a bit confusing.
So basically to get it working you can either put your middleware before an actual existing middleware or just use
config.middleware.use
instead of
config.middleware.insert_before

Devise 3.0.0rc custom attributes and strong parameters in Rails 4

I used this solution based on devise_parameter_sanitizer to set some custom attributes to my Devise (User) model and make them available at sign_up and edit forms.
Everything works fine but from time to time (and it happens pretty often) specifically when I sign in, sign out or edit user (so I assume the problem is related to sessions), I get the following error:
Is there any logic that I can add to my code above to present this issue?
I know this was a little while ago but wanted to put an answer here because this actually took me a bit to solve and other people might have a similar issue.
Because you used an initializer to load the User:ParameterSanitizer when you change the application controller or anything that would cause it to reload (because you are in debug mode) the initialization is lost.
This is easy to test to confirm this is what was happening to you:
First: start the server fresh and go to your login page: should work.
Next: modify application_controller.rb (just put a space somewhere and hit save)
Next: visit your login page again (not working anymore) :(

Rails UserRegistrationsController not Inheriting from Devise::RegistrationsController

I'm pretty new to Rails, but followed the excellent suggestion/walkthrough here. I've gotten the creation of my two user types (Clients and Developers) to work successfully with Devise. However, I also want to allow both user types to edit some of their attributes after they are logged in. These attributes are also specific to their user types (client specific fields or developer specific fields).
To do this, I thought that I needed to create a custom update in user_registrations_controller which inherits from Devise::RegistrationController as would make sense. During my customization however, I realize within update I am unable to call other default methods from Devise::RegistrationController. As a sanity check, I overrode update with an exact copy of the update method as defined in the original Devise::RegistrationController and still had this issue.
More specifically, the error I receive is: undefined local variable or method 'account_update_params' for #<UserRegistrationsController:0x007fe4f0342d58>, despite account_update_params being a method in the inherited controller.
Is there a better way to edit the fields specific to my user types (client/developer) in Devise without having to customize update? Also, what is going on with this error here, as I believe I am inheriting from Devise::RegistrationController?
Any thoughts? Help and suggestions much appreciated! =)
Versions: Rails 3.2.12, ruby 1.9.3p249
After revisiting this, I found this related question. Though this post and top answer is specific to Rails 4, the solution can be found in the Gemfile.
Replace your devise gem include with
gem 'devise', :git => 'git://github.com/plataformatec/devise.git'
Simply doing gem 'devise' does not get this updated version, unfortunately. Hope this helps others!

Cannot get devise_oauth2_canvas_facebook to work

I'm getting a "TypeError in Devise::FacebookConsumersController#callback: can't convert Hash into Integer" when I try to authenticate using Devise and devise_oauth2_canvas_facebook gem with the new Facebook API. Any ideas what can be the problem?
It look like mooktakim the creator of the devise_oauth2_canvas_facebook gem is not updating it anymore.
Here is his message on a pull request to that effect:
https://github.com/mooktakim/devise_oauth2_facebook/pull/9
He says that he is moving to Omnisocial
https://github.com/icelab/omnisocial#readme
This uses Omniauth which allows you to use logins from many different sources.
It might be better for you to move to Omniauth.

ROR 3 Michael Hartl tutorial - assign Admin role invalidates the user

I am experiencing an issue as I am following Michael Hartl's tutorial and currently at the end of Chapter 10.
When I use toggle in the rails console to flip the admin property of a user from false to true (I'm trying to create an Admin user), I am successful in doing so; however that user becomes invalid - when I try to log in to the application with this user's credential I am getting an error that the credentials are incorrect (even though they are)
Just from checking the logs and the looking at the terminal, it seems the authenticity token is either missing or incorrect - any ideas what I am doing wrong here?
I tried following the tutorial as close as possible, I doubt I missed something, but its obviously possible.
I have had a similar problem as well. It appears (and perhaps someone else can explain why) that when you run user.toggle!(:admin), it resets the password to ''. To fix it I just ran user.update_attributes(:password => "yourpassword", :password_confirmation => 'yourpassword in the console.
Yes. I too stumbled here. Part of what made this puzzling to me as a newcomer to rails was that the error was in my understanding of how the testing sqlite db is handled, not the code that was written. I thought I was guaranteed a fresh start (new copy of project_root/db/test.sqlite3) each time testing began, but this is not always the case. More here:
Rails 3 Tutorial Chapter 11 "Validation failed: Email has already been taken" error
and here:
RailsTutorial - chapter 8.4.3 - Test database not clearing after adding user in integration test
and here:
http://rubygems.org/gems/database_cleaner (click on 'Documentation')
Most of these discussions surrounds the testing db, but the exchange also clued me in to the existence of development and production databases as well. Look at your directory listing for project_root/db for your ah-ha! moment.
hth,
Perry
I got it to work, but I still don't understand how it comes about and whether its by design or not. But, I did manage to register an Admin user, my mistake was that I didn't set the password field in the console before calling user.toggle!(:admin).
i.e.
u = User.find_by_id(1)
u.password = "password"
u.toggle!(:admin)
and it worked.