设计确认链接不起作用

时间:2014-09-10 07:14:25

标签: ruby-on-rails ruby ruby-on-rails-3 heroku devise

真的很恼火。在我的Rails应用程序中,所有电子邮件都通过Mandrill通过SMTP发送出去;应用程序本身托管在Heroku上。对于Devise gem来说,一切似乎都能正常工作 - 用户可以注册,登录等。但是,电子邮件中包含的确认链接不起作用。

看起来像这样:

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

当我单击链接并检查日志时,似乎唯一发生的事情是用户被定向到站点的根目录。永远不会加载ConfirmationsController #show action。

我真的不确定问题是什么。在我的routes.rb文件的开头我有这个:

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

我用这个覆盖了RegistrationsController:

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

我在这里做错了什么想法?

编辑:佣金路线的结果| grep确认

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    

添加日志,这是新用户点击确认链接时发生的情况

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 个答案:

答案 0 :(得分:3)

您的ssl配置错误

如果您想发送链接: http://anymarket.co/users/confirmation?confirmation_token=1fde79fe312eec0efc733e77f946aba5d7b227cbdfeb54e429f9a0e6f369a5cd

有两个问题,首先你得到纯http端口80未加密协议,但你配置了ssl,所以你被重定向到https协议。第二个是您将www.anymarket.co配置为ssl端点而不是anymarket.co,因为您在子域上获得了索引页面。 你可以用curl测试它:

curl -kvI https://anymarket.co

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

换句话说,您邮件中的链接应该是这样的

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