Devise Custom Routes and Login Pages

With Devise 1.1.3 the following should work devise_for :user, :path => ”, :path_names => { :sign_in => “login”, :sign_out => “logout”, :sign_up => “register” } The routes it creates will not be appended with “/user/…” because of the :path parameter being an empty string. The :pathnames hash will take care of naming the routes as … Read more

Devise “Confirmation token is invalid” when user signs up

So upgrading to Devise 3.1.0 left some ‘cruft’ in a view that I hadn’t touched in a while. According to this blog post, you need to change your Devise mailer to use @token instead of the old @resource.confirmation_token. Find this in app/views/<user>/mailer/confirmation_instructions.html.erb and change it to something like: <p>Welcome <%= @resource.email %>!</p> <p>You can confirm … Read more

Rails, Devise authentication, CSRF issue

Jimbo did an awesome job explaining the “why” behind the issue you’re running into. There are two approaches you can take to resolve the issue: (As recommended by Jimbo) Override Devise::SessionsController to return the new csrf-token: class SessionsController < Devise::SessionsController def destroy # Assumes only JSON requests signed_out = (Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name)) render … Read more

Devise API authentication [closed]

There is a devise configuration called :token_authenticatable. So if you add that to the devise method in your “user”, then you can authenticate in your API just by calling “/api/v1/recipes?qs=sweet&auth_token=[@user.auth_token]” You’ll probably want this in your user as well: before_save :ensure_authentication_token UPDATE (with API authorization code) The method you’re looking for are: resource = User.find_for_database_authentication(:login=>params[:user_login][:login]) … Read more

Creating an admin user in Devise on Rails beta 3

Yup. I feel dumb. If anyone else is having a similarly vapid moment. Just use the rails console to create the admin user: ➡ rails c Loading development environment (Rails 3.0.0.beta3) irb(main):001:0> admin = Admin.create! do |u| irb(main):002:1* u.email=”sample@sample.com” irb(main):003:1> u.password = ‘password’ irb(main):004:1> u.password_confirmation = ‘password’ irb(main):005:1> end That will do it. Now just … Read more

Devise: Disable password confirmation during sign-up

To disable password confirmation you can simply remove the password_confirmation field from the registration form. This disables the need to confirm the password entirely! Generate devise views if you haven’t: rails g devise:views Remove the password_confirmation section in app\views\devise\registrations\new.html.erb The reason why this works lies in lib/devise/models/validatable.rb in the Devise source: module Devise module Models … Read more