gpt4 book ai didi

ruby-on-rails-3 - 覆盖设计密码 Controller

转载 作者:行者123 更新时间:2023-12-03 23:37:01 24 4
gpt4 key购买 nike

我想禁用

  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 gem 。

当我单击忘记密码的链接时,出现此错误
Started GET "/users/password/new" for 127.0.0.1 at 2012-11-16 10:21:07 +0200

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

我的 rake routes
              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

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

我想念什么?

最佳答案

密码 Controller 是从设计密码 Controller 扩展而来的。因此,用设计密码控制程序扩展密码控制程序。

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

end

使用devise更改密码 Controller 的路由
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

关于ruby-on-rails-3 - 覆盖设计密码 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13412903/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com