加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails-3 – 覆盖设计密码控制器

发布时间:2020-12-17 04:00:43 所属栏目:百科 来源:网络整理
导读:我想禁用 def create self.resource = resource_class.send_reset_password_instructions(resource_params) if successfully_sent?(resource) respond_with({},:location = after_sending_reset_password_instructions_path_for(resource_name)) else respon
我想禁用

def create
    self.resource = resource_class.send_reset_password_instructions(resource_params)

    if successfully_sent?(resource)
      respond_with({},:location => after_sending_reset_password_instructions_path_for(resource_name))
    else
      respond_with(resource)
    end
  end

因此在发送重置密码后根本不会重定向

所以,我在app / controllers / users /下创建了一个名为passwords_controller.rb的新文件

看起来像这样

class User::PasswordsController < Devise::PasswordsController

    def create
    self.resource = resource_class.send_reset_password_instructions(resource_params)

            if successfully_sent?(resource)
            flash[:notice] = "sent password"
            else
              respond_with(resource)
            end
        end

        def new
            super
        end

        def update
            super

        end
        def edit
            super

        end
    end

并改变了我的路线

devise_for :users,:controllers => { :invitations => 'users/invitations',:passwords => 'users/passwords' }

我也有devise_invite宝石..

当我点击忘记密码的链接时,我收到此错误

Started GET "/users/password/new" for 127.0.0.1 at 2012-11-16 10:21:07 +0200

ActionController::RoutingError (uninitialized constant Users::PasswordsController):

我的佣金路线是

user_password POST   /users/password(.:format)                  users/passwords#create
          new_user_password GET    /users/password/new(.:format)              users/passwords#new
         edit_user_password GET    /users/password/edit(.:format)             users/passwords#edit
                            PUT    /users/password(.:format)                  users/passwords#update

视图中的链接是

<%= link_to "Forgot your password?",new_password_path(User),:class => "control-group",:style => "position: absolute; bottom: 0",:id=>"forgotpass" %>

我错过了什么?

解决方法

密码控制器从设计密码控制器扩展.因此,使用设计密码控制器扩展密码控制器.

class PasswordsController < Devise::PasswordsController
  ......................

end

使用devise更改密码控制器的路由

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

路线将是这样的: –

user_password       POST   /password(.:format)       Passwords#create

new_user_password   GET    /password/new(.:format)   Passwords#new

edit_user_password  GET    /password/edit(.:format)  Passwords#edit
                    PUT    /password(.:format)       Passwords#update

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读