1

I have recently added confirmable to my rails application with devise. It is all working smoothly however when I create a new user I am getting the

signed_up: "Welcome! You have signed up successfully."

rather than

signed_up_but_unconfirmed:"A message with a confirmation link has been sent to your email address. Please follow the link to activate your account."

even though they are unconfirmed. Was there something I needed to do when adding confirmable to change this? Thanks!

UPDATE

I am using my own user controller and routing it like so below:

routes.rb

  devise_for :users, :controllers => {:registrations => "users"}

  devise_scope :user do
    get 'users/:id' => 'users#show', as: "user"
  end
MikeHolford
  • 1,851
  • 2
  • 21
  • 32
  • There are so many different versions and ways to use Devise, so it is hard to help you with the given information. E.g.: Did you generate custom Devise controllers or do you use the default ones given from the Gem? – Sebastian vom Meer Mar 27 '15 at 12:03
  • Apologies I should have given more info. I am using my own views and I have created a user controller see edit above – MikeHolford Mar 27 '15 at 13:02

1 Answers1

0

You could have your routes with this

as :user do
    patch '/users/confirmation' => 'users/confirmations#update', :via => :patch, :as => :update_user_confirmation
end

and have the confirmations_controller with the following:

class Users::ConfirmationsController < Devise::ConfirmationsController
  skip_before_filter :authenticate_user!
  before_action :check_if_current_user

  # PUT /resource/confirmation
  def update
    with_unconfirmed_confirmable do
      if @confirmable.has_no_password?
        @confirmable.attempt_set_password(params[:user])
        if @confirmable.valid? && @confirmable.password_match?
          do_confirm
        else
          do_show
          @confirmable.errors.clear #so that we wont render :new
        end
      else
        self.class.add_error_on(self, :email, :password_already_set)
      end
    end

    if !@confirmable.errors.empty?
      render 'devise/confirmations/new' #Change this if you don't have the views on default path
    end
  end

  # GET /resource/confirmation?confirmation_token=abcdef
  def show
    with_unconfirmed_confirmable do
      if @confirmable.has_no_password?
        do_show
      else
        do_confirm
      end
    end
    if !@confirmable.errors.empty?
      self.resource = @confirmable
      render 'devise/confirmations/new' #Change this if you don't have the views on default path
    end
  end

  protected

  def with_unconfirmed_confirmable
    original_token = params[:confirmation_token]
    confirmation_token = Devise.token_generator.digest(User, :confirmation_token, original_token)
    @confirmable = User.find_or_initialize_with_error_by(:confirmation_token, confirmation_token)
    if !@confirmable.new_record?
      @confirmable.only_if_unconfirmed { yield }
    end
  end

  def do_show
    @confirmation_token = params[:confirmation_token]
    @requires_password = true
    self.resource = @confirmable
    render 'devise/confirmations/show' #Change this if you don't have the views on default path
  end

  def do_confirm
    @confirmable.confirm!
    set_flash_message :notice, :confirmed
    sign_in_and_redirect(resource_name, @confirmable)
  end

  def check_if_current_user
    if current_user.present?
      render :file => "#{Rails.root.to_s}/public/confirmed.html", :status => :unauthorized
    end
  end

end

Hope it is helpful.

sansarp
  • 1,446
  • 11
  • 18