New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
current_user not available in "visible do" block #549
Comments
Try bindings[:view].controller.current_user or just bindings[:view].current_user |
bbenezech, thanks for the suggestion. Unfortunately it did not work. I YAML::dump'd the bindings variable in the visible block and it was null, as well as bindings[:view] ... I guess that's only available in the config.edit block? |
Assigning @kaapa, since config is his "zone". |
Are you sure that 'visible' is the right thing to use? I use 'show' in both the list and edit blocks and it works fine:
|
Fixed meanwhile |
I'm still having this exact problem config.current_user_method do
current_admin
end
config.model Admin do
show do
field :id
field :email
field :last_sign_in_ip do
visible do
current_user.email == "foo@bar.com"
end
end
end
end Which gives me: undefined local variable or method `current_user' for #RailsAdmin::Config::Fields::Types::String:0x79a0ce4c Anybody have any ideas? |
You can call your current_admin or rails_admin's _current_user. |
Both of those result in a similar undefined local variable error ( for _current_user or current_admin, respectively) Sent from my iPad On Nov 12, 2011, at 5:29 AM, Benoit Bénézechreply@reply.github.com wrote:
|
bindings[:view]._current_user |
Great, that seems to work. Thanks! Cheers, Sasha On Sun, Nov 13, 2011 at 11:52 PM, Benoit Bnzech <
Sasha Voynow |
_current_user is the RailsAdmin mapping of your current_admin method. Cheers! |
Does not work in my case: list do
include_fields :id, :title, :body
field :admin_user do
visible do
bindings[:view]._current_user.super_admin?
end
end It gives me For show and edit configs this constructions works fine. |
But it worked when I used bindings[:view].current_admin_user.super_admin? admin_user is my user model name. |
Shouldn't be private. Use send meanwhile. |
There is a helper method for _current_user: And there is a test case that passes: https://github.com/sferik/rails_admin/blob/master/spec/requests/rails_admin_spec.rb#L51 You say it only happens with list, I'm gonna have a look. |
Hello, The method _current_user is still not public. config.model 'Model' do
visible do
# this does not work, _current_user is private
bindings[:controller]._current_user.admin
end
end binding[:view] cannot be used in that scope either. Thank you |
@RedXVII +1 |
@RedXVII +1 |
RedXVII +1 |
@RedXVII +10 |
Not sure if this is the right place to post this but figure I'd try anyway.
I'm trying to implement something similar to this:
I know in the README it says the example is theoretical, but I keep getting that current_user is not found within that block. I'm authorizing with CanCan:
RailsAdmin.authorize_with :cancan
At the top of rails_admin.rb in config/initializers
Can anyone tell me how to get current_user available within the visible block? I'd like to only show certain fields in the "List" view if a user is an admin.
The text was updated successfully, but these errors were encountered: