【问题标题】:current_user not accessible in Batch_Action form block在 Batch_Action 表单块中无法访问 current_user
【发布时间】:2019-12-19 05:21:35
【问题描述】:

尝试访问 batch_actionform 块中的 current_user,如下所示:

batch_action 'Change Status', confirm: 'Mass-Assign Status', 
form: {'Location' => City.where(:company_id => current_user.company_id).map{|s| [s.to_s, s.id]}} 
do |selection, inputs|
    //---- Code ----- (current_user can be accessed over here successfully)
end

我收到的错误是undefined local variable or method current_user for #<ActiveAdmin::ResourceDSL:0x00007f814b3e0db8> (NameError)

但我可以轻松访问 do-end 块中的 current_user。

  • Ruby 版本:2.5.5p157
  • Rails 版本:4.2.11.1
  • 活动管理员

【问题讨论】:

  • 你解决了吗?

标签: ruby-on-rails activeadmin cancan


【解决方案1】:

我认为在这种情况下无法访问该变量。

尝试使其全球化并使用。

#config/initializers/active_admin.rb

ActiveAdmin.setup do |config|
  config.before_filter do
    $current_admin_user = current_admin_user
  end
end

【讨论】:

  • 你做了什么?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-11-29
  • 1970-01-01
  • 1970-01-01
  • 2014-11-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多