2
votes

Really annoyed here. In my Rails app, all emails are sent out over SMTP via Mandrill; the app itself is hosted on Heroku. Everything seems to work fine in regards to the Devise gem -- users can sign up, log in etc. However, the confirmation link included in emails DOES NOT WORK.

It looks like this:

http://anymarket.co/users/confirmation?confirmation_token=1fde79fe312eec0efc733e77f946aba5d7b227cbdfeb54e429f9a0e6f369a5cd

When I click the link and check the logs, it appears that the only thing that happens is the user is directed to the root of the site. The ConfirmationsController#show action is never loaded.

I'm really unsure of what the problem is. At the beginning of my routes.rb file I have this:

devise_for :users, :controllers => { :registrations => 'registrations' }
default_url_options :host => "anymarket.co"

I override the RegistrationsController with this:

class RegistrationsController < Devise::RegistrationsController
  before_filter :authenticate_user!, :except => [:after_inactive_sign_up_path_for]

    def new 
        respond_to do |format|
            format.js
            format.html
        end
    end

    def create
    build_resource(sign_up_params)

    resource_saved = resource.save
    yield resource if block_given?
    if resource_saved
      if resource.active_for_authentication?
                set_flash_message :onboard, :signed_up if is_flashing_format?
        sign_up(resource_name, resource)
        respond_with resource, location: after_sign_up_path_for(resource)
      else
                set_flash_message :onboard, :"signed_up_but_#{resource.inactive_message}" if is_flashing_format?
        expire_data_after_sign_in!
        respond_with resource, location: after_inactive_sign_up_path_for(resource)
      end
    else
      clean_up_passwords resource
      @validatable = devise_mapping.validatable?
      if @validatable
        @minimum_password_length = resource_class.password_length.min
      end
      respond_with resource
    end
  end

  def after_inactive_sign_up_path_for(user)
        respond_to do |format|
             format.html {render :action => "/"}
    end
  end

    private

  def sign_up_params
    params.require(:user).permit(:first_name, :last_name, :email, :password, :password_confirmation, :avatar, :school, :provider, :uid)
  end

  def account_update_params 
    params.require(:user).permit(:first_name, :last_name, :email, :password, :password_confirmation, :current_password, :avatar, :braintree_customer_id)
  end

end

Any ideas what I'm doing wrong here??

Edit: result of rake routes | grep confirmation

user_confirmation POST   /users/confirmation(.:format)              devise/confirmations#create                                                                  
    new_user_confirmation GET    /users/confirmation/new(.:format)          devise/confirmations#new                                                                     
                          GET    /users/confirmation(.:format)              devise/confirmations#show    

Tailed the logs, this is what happens when a new user clicks the confirmation link

Started GET "/" for 98.245.3.223 at 2014-09-10 07:29:36 +0000                                                               
2014-09-10T07:29:36.706263+00:00 app[web.1]:   Rendered home/index.html.erb within layouts/application (104.6ms)                                                         
2014-09-10T07:29:36.709496+00:00 app[web.1]: Completed 200 OK in 112ms (Views: 96.9ms | ActiveRecord: 12.6ms)                                                            
2014-09-10T07:29:36.597154+00:00 app[web.1]: Processing by HomeController#index as HTML                                                                                  
2014-09-10T07:29:36.708971+00:00 app[web.1]:   Rendered layouts/_no_cc_alert.html.erb (0.2ms)                                                                            
2014-09-10T07:29:36.718357+00:00 heroku[router]: at=info method=GET path="/" host=www.anymarket.co request_id=a42fa3d1-f7a2-4871-92d7-14278f93cae7 fwd="98.245.3.223" dyn
o=web.1 connect=2ms service=126ms status=200 bytes=1036  
1
Please execute rake routes | grep confirmation and display the result in your post.pierallard
@ForgetTheNorm - okay, updated itTom Maxwell
Weird. You say that a GET into http://anymarket.co/users/confirmation?... routes to your root, but your configurations seems to route to devise/confirmations#show. What's exaclty the complete log when user click on this link ?pierallard
Updated with the tail for that. Not much happens, but a render of the "/" root. Could it be related to my after_inactive_sign_up_path_for(user) action in the RegistrationsController?Tom Maxwell
Update: nope. I have no idea what the problem is.Tom Maxwell

1 Answers

3
votes

Your ssl config is wrong

if you want to send a link: http://anymarket.co/users/confirmation?confirmation_token=1fde79fe312eec0efc733e77f946aba5d7b227cbdfeb54e429f9a0e6f369a5cd

There are two problems, first you get pure http port 80 unencrypted protocol, but you configured ssl so you get redirected to https protocol. Second one is that you configured www.anymarket.co to be ssl endpoint not anymarket.co because of that you are getting index page on subdomain. You can test it with curl:

curl -kvI https://anymarket.co

and

curl -kvI https://www.anymarket.co

In other words your link in mail should be like this one

https://www.anymarket.co/users/confirmation?confirmation_token=1fde79fe312eec0efc733e77f946aba5d7b227cbdfeb54e429f9a0e6f369a5cd