rails:3 Devise signup Filter chain halted as :require_no_authentication rendered or redirected

The mentioned line on Devise’s Controller makes sense in general cases: a logged in user can’t sign up. As you’re on a case where only an admin can create a user, I would suggest that you don’t use Devise’s controller on Registerable module and write your own controller with your own rules. You can write … Read more

Devise token_authenticatable deprecated, what is the alternative?

I wanted to keep backwards compatibility so I just moved everything into a concern to avoid the warning. Here’s my code and associated specs: /app/models/concerns/token_authenticatable.rb module TokenAuthenticatable extend ActiveSupport::Concern module ClassMethods def find_by_authentication_token(authentication_token = nil) if authentication_token where(authentication_token: authentication_token).first end end end def ensure_authentication_token if authentication_token.blank? self.authentication_token = generate_authentication_token end end def reset_authentication_token! self.authentication_token = … Read more

How do I make a before_action to run on all controllers and actions except one?

What you have to do is to set autheticate_user! on all controllers like that : class ApplicationController < ActionController::Base before_action :authenticate_user! … end And then on your HomeController you do that : class HomeController < ApplicationController skip_before_action :authenticate_user!, only: [:index] … end Hope this will help you !

How to do integration testing with RSpec and Devise/CanCan?

@pschuegr’s own answer got me across the line. For completeness, this is what I did that gets me easily set up for both request specs and controller specs (using FactoryGirl for creating the user instance): in /spec/support/sign_in_support.rb: #module for helping controller specs module ValidUserHelper def signed_in_as_a_valid_user @user ||= FactoryGirl.create :user sign_in @user # method from … Read more

How to auto-generate passwords in Rails Devise?

Use the Devise.friendly_token method: password_length = 6 password = Devise.friendly_token.first(password_length) User.create!(:email => ‘someone@something.com’, :password => password, :password_confirmation => password) FYI: Devise.friendly_token returns a 20 character token. In the example above, we’re chopping off the first password_length characters of the generated token by using the String#first method that Rails provides.

Rails + Devise – Is there a way to BAN a user so they can’t login or reset their password?

From the devise doku for authenticatable.rb: Before authenticating a user and in each request, Devise checks if your model is active by calling model.active_for_authentication?. This method is overwriten by other devise modules. For instance, :confirmable overwrites .active_for_authentication? to only return true if your model was confirmed. You overwrite this method yourself, but if you do, … Read more