凡覆盖色器件宝石CURRENT_USER helper方法 [英] Where to override current_user helper method of devise gem
问题描述
我怎么可以重写 CURRENT_USER 的设计的宝石。 的
其实我需要为移动应用添加Web服务。
How can i override current_user of devise gem. Actually I need to add web services for mobile-app.
目前设计是管理会议和Web的应用程序的CURRENT_USER。
Currently devise is managing session and 'current_user' for web-application.
现在移动应用将发送USER_ID到服务器。我需要重写当前用户喜欢这个
Now Mobile app will send user_id to the server. I need to override current user like this
def current_user
if params[:user_id].blank?
current_user
else
User.find(params[:user_id])
end
end
我应该需要修改色器件创业板插件?还是其他什么东西?结果
详细,因为我在铁轨新解释亲切。
Should I need to modify devise gem as plugin ? or something else ?
Kindly explain in detail as I am new in rails.
亲切的问候,
推荐答案
据模块<一个href=\"https://github.com/plataformatec/devise/blob/master/lib/devise/controllers/helpers.rb\">Devise::Controllers::Helpers, CURRENT_USER
(与所有其他色器件助手一起)被添加到ApplicationController中,这意味着你可以用这种方式重写它:
According to the module Devise::Controllers::Helpers, current_user
(together with all other devise helpers) is added to ApplicationController, which means that you can override it in this way:
# in application_controller.rb
alias_method :devise_current_user, :current_user
def current_user
if params[:user_id].blank?
devise_current_user
else
User.find(params[:user_id])
end
end
这篇关于凡覆盖色器件宝石CURRENT_USER helper方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!