我正在尝试允许管理员用户有能力在某个用户的眼中看到current_user
我创建了一个似乎不起作用的before_filter:
class IntegrationsController < ApplicationController
before_filter :change_user
def index
Rails.logger.error current_user.email
@integrations = current_user.integrations
@reports = current_user.reports
# mixpanel_tracker.track(current_user.id, "Index of Integration")
end
private
def change_user
if params[:current_user]
return current_user = User.find(params[:current_user])
end
end
end
我的index.html.erb包含:
<%= form_tag integrations_path, method: :get do %>
<%= select_tag :current_user, options_from_collection_for_select(User.all, 'id', 'email') %>
<%= submit_tag "Submit" %>
<% end %>
在我的Rails日志中,当应该是所选用户时,我得到current_user
作为管理员用户。当我这样做时,它有效:
def index
if params[:current_user]
return current_user = User.find(params[:current_user])
end
Rails.logger.error current_user.email
@integrations = current_user.integrations
@reports = current_user.reports
# mixpanel_tracker.track(current_user.id, "Index of Integration")
end