I am using Devise in a rails app for User Auth. I have already created both the registrations and sessions controller, but now I want a controller that simulates the def update
from scaffolding. Is there a way to access the controller that Devise uses to 开发者_StackOverflow社区update a user?
Yes, you can subclass the registrations_controller used by devise to edit users and do whatever you want with the update action, this is the subclassed controller with the default update action in it:
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
精彩评论