Closed Ellerden closed 4 years ago
The best way to use current_user
fo scope control is like this:
def index
@grid = CandidatesGrid.new(params[:candidates_grid]) do |s|
s.where("users.id = ?", current_user.id).page(params[:page])
end
end
If you still want current_user
to be inside Grid for any purpose, define it as filter:
filter(:current_user) do
where('users.id = ?', current_user.id)
end
Yeah, I will need current_user
only for one filter, not for the whole scope of candidates.
I found a way around it — since I at least needed current_user id to make my filter work and to avoid stack level is too deep error.
in controller:
current_user_id = current_user.id
and then passing to the gridcurrent_user_id
instead of current_user
in CandidatesGrid:
attr_accessor :current_user_id
filter(
:followed,
:enum,
select: ['Followed'],
checkboxes: true
) do |_value, scope, grid|
scope.joins(:followers).where('users.id = ?', grid.current_user_id)
end
Hello again :) I'm trying to access from the filter
current_user
that passed to my CandidatesGrid. I've read docs, this Issue and several others about select. It all works if select is not a checkbox, I guess – or I couldn't find a way around it. My filter looks like this and I get "undefined local variable or method `current_user'" , but if I replace it with some user.id it works. What could be wrong? Thanks for your help!