【问题标题】:Rails Devise After Sending Password Reset Instructions it redirects to the wrong pageRails Devise 在发送密码重置指令后重定向到错误的页面
【发布时间】:2012-07-19 22:42:03
【问题描述】:

我在我的 rails 应用程序中使用设计。出于某种原因,当您单击“发送密码重置说明”按钮时,输入您的电子邮件后,它会将您带到一个空白页面,此 URL 为 /users/password.user。我不知道它为什么这样做,也不知道如何改变它。

我不确切知道要发布什么代码,所以只需评论您希望我添加的摘录。谢谢。

作为记录,密码重置电子邮件和更改密码令牌完美运行,它只是这个奇怪的重定向(或缺少重定向)。

这些是路线:

devise_for :users, :controllers => {:registrations => 'registrations', :invitations => 'invitations', :confirmations => 'confirmations'}, :except => [:show]

密码路径助手是edit_password_url(@resource, :reset_password_token => @resource.reset_password_token)

config.reset_password_keys:

config.reset_password_keys = [ :login ]

密码重置表格:

            <head>
              <%= stylesheet_link_tag "passreset" %>  
            </head>

            <body>

                <div id="box">
                        <%= form_for(resource, :as => resource_name, :url => user_password_path(resource_name), :html => { :method => :post }) do |f| %>
                            <%= devise_error_messages! %>

                                <%= f.text_field :id,:name => "user[login]", :placeholder => "Username or Email"%>

                                <input name="commit" type="submit" name="" value="Submit" />
                        <% end %>
                </div>
            </body>

【问题讨论】:

  • 你能发布你的路线吗? (或至少只是设计和用户部分),以及重置密码电子邮件模板中的路径助手
  • 抱歉更新晚了,不在城里。这是我认为你想要的,如果你想要更多,请告诉我。谢谢。
  • 对不起,我认为这是您重置密码电子邮件中的错误链接,您可以发布您的 config.reset_password_keys(在设计配置文件中)和您的重置密码表单
  • 再次,抱歉更新晚了(这次真的晚了)。无论如何,就像我说的,正在发送电子邮件。它只是与单击“发送”按钮后有关,它会将您带到一个空白页面。
  • 刷新将发送另一封电子邮件。

标签: ruby-on-rails email devise passwords


【解决方案1】:

如果我理解正确,您似乎需要编辑视图或设计初始化文件 => config/initializers/devise.rb

您可以通过运行设计生成器来编辑您的视图 rails generate devise:views users

希望对你有帮助

【讨论】:

    【解决方案2】:

    我们遇到了类似的问题。对我们来说,事实证明,当我们编辑自己的帐户时,Devise 正在注销我们。我们使用了 sign_in() 设计助手并最终使用了以下代码:

    用户控制器

    定义更新

    # need to know if user is changing their own password for re-sign in purposes.
    is_current_user =  (@user == current_user)
    
    password_change = !params[:user][:password].empty?
    if (password_change)
      @user.update_with_password(params[:user])
    else
      @user.update_without_password(params[:user])
    end
    
    if is_current_user # Devise signs us out, so...
      sign_in(@user, :bypass => true)
    end
    
    
    @user.has_temp_password = false
    @user.save!
    
    if is_current_user
      redirect_to root_path, notice: 'Your account was successfully updated.'
    else
      redirect_to users_path, notice: 'The user was successfully updated.'
    end
    

    结束

    【讨论】:

      【解决方案3】:

      尝试将表单中的网址更改为

      :url => password_path(resource_name)
      

      【讨论】:

        猜你喜欢
        • 2014-11-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-08-19
        • 1970-01-01
        • 1970-01-01
        • 2017-11-17
        • 1970-01-01
        相关资源
        最近更新 更多