acceptable-cartoon-88076
07/15/2023, 7:58 PMacceptable-cartoon-88076
07/15/2023, 7:59 PMacceptable-cartoon-88076
07/15/2023, 7:59 PMhttps://cdn.discordapp.com/attachments/1129864672351367248/1129864895710634024/image.pngâ–¾
acceptable-cartoon-88076
07/15/2023, 7:59 PMhttps://cdn.discordapp.com/attachments/1129864672351367248/1129864956406403132/image.pngâ–¾
acceptable-cartoon-88076
07/15/2023, 8:00 PMloud-jewelry-99127
07/16/2023, 10:30 AMcontext[:user].admin?
lemon-wall-20836
07/16/2023, 1:20 PMavo.rb
config.set_context
settingacceptable-cartoon-88076
07/16/2023, 3:36 PMconfig.set_context do
{
foo: "bar",
user: current_user,
params: request.params
}
end
However, now I have a new problem.
This syntax, copied from the docs, and applied to an id field:
field :id, as: :id, visible: -> (resource:) { context[:user].is_admin? }
generates an Argument error
wrong number of arguments (given 1, expected 0)
If I replace the context[] call with a boolean, it works fine, but calling context causes the error.acceptable-cartoon-88076
07/16/2023, 3:37 PMhttps://cdn.discordapp.com/attachments/1129864672351367248/1130161315181244466/image.pngâ–¾
acceptable-cartoon-88076
07/16/2023, 3:41 PMlemon-wall-20836
07/17/2023, 5:39 AMruby
field :id, as: :id, visible: -> (resource:) {
puts ['context->', context].inspect;
true
}
lemon-wall-20836
07/17/2023, 5:39 AMputs
statement in the rails consoleacceptable-cartoon-88076
07/17/2023, 1:51 PMhttps://cdn.discordapp.com/attachments/1129864672351367248/1130497120944791673/image.pngâ–¾
lemon-wall-20836
07/17/2023, 1:53 PMlemon-wall-20836
07/17/2023, 1:53 PMputs
loud-jewelry-99127
07/17/2023, 2:05 PMloud-jewelry-99127
07/17/2023, 2:06 PMwith_options only_on: :index
....loud-jewelry-99127
07/17/2023, 2:06 PMfield :id, as: :id, visible: -> (resource:) { resource.view == :index && context[:user].is_admin?}
acceptable-cartoon-88076
07/17/2023, 2:06 PMacceptable-cartoon-88076
07/17/2023, 2:06 PMacceptable-cartoon-88076
07/17/2023, 2:06 PMloud-jewelry-99127
07/17/2023, 2:07 PMacceptable-cartoon-88076
07/17/2023, 2:07 PMloud-jewelry-99127
07/17/2023, 2:45 PMwith_options only_on: :index do |only_index|
only_index.field :id, as: :id, visible: -> (resource:) { context[:user].is_admin?}
end
acceptable-cartoon-88076
07/17/2023, 4:40 PMacceptable-cartoon-88076
07/17/2023, 4:41 PMacceptable-cartoon-88076
07/17/2023, 4:41 PMloud-jewelry-99127
07/17/2023, 5:49 PMonly_index
to whatever fits