【发布时间】:2011-09-02 13:56:02
【问题描述】:
我在 Rails 应用程序中使用 Devise 进行用户身份验证。我已经创建了注册和会话控制器,但现在我想要一个从脚手架模拟def update 的控制器。有没有办法访问 Devise 用来更新用户的控制器?
【问题讨论】:
-
我认为设计在注册控制器中执行用户更新
标签: ruby-on-rails devise scaffolding
我在 Rails 应用程序中使用 Devise 进行用户身份验证。我已经创建了注册和会话控制器,但现在我想要一个从脚手架模拟def update 的控制器。有没有办法访问 Devise 用来更新用户的控制器?
【问题讨论】:
标签: ruby-on-rails devise scaffolding
是的,您可以对设计使用的 registrations_controller 进行子类化,以编辑用户并使用更新操作做任何您想做的事情,这是包含默认更新操作的子类化控制器:
class Users::RegistrationsController < Devise::RegistrationsController
def update
self.resource = resource_class.to_adapter.get!(send(:"current_#{resource_name}").to_key)
if resource.update_with_password(params[resource_name])
set_flash_message :notice, :updated if is_navigational_format?
sign_in resource_name, resource, :bypass => true
respond_with resource, :location => after_update_path_for(resource)
else
clean_up_passwords(resource)
respond_with_navigational(resource){ render_with_scope :edit }
end
end
end
【讨论】: