答案 0 :(得分:3)
使用helper_method,如您所见:helpers.rb和吼叫:
ActiveSupport.on_load(:action_controller) do
helper_method "current_#{mapping}", "#{mapping}_signed_in?", "#{mapping}_session"
end
如果您按current_user
搜索该文件,则无法找到任何内容,因为设计使用mapping
占位符允许您执行以下操作:
rails generate devise User # this will generate 3 helpers: current_user, user_signed_in? and user_session
或
rails generate devise Blogger # this will generate 3 helpers: current_blogger, blogge_signed_in? and blogger_session