开发者

Update Controller of Devise

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜