在 batch_action 中使用 lambda 时出错(活动管理员,Rails 5)
Error using lambda in batch_action (Active Admin, Rails 5)
我想在 Active Admin 中的 batch_action 中使用 lambda 时遇到问题。此错误仅在我使用 lambda 时出现,因为当我使用块时错误消失但列表未更新。这是我的代码
batch_action :set_cohorts, form: -> {{cohort: Cohort.order(:name).pluck(:name, :id)}} do |ids, inputs|
cohort = Cohort.find(inputs[:cohort])
end
form do |f|
inputs 'Sección' do
f.semantic_errors
input :cohort, as: :select, collection: -> {Cohort.order(:name).pluck(:name, :id)}
input :name
input :position
input :active, as: :radio
end
f.actions
end
错误是
wrong number of arguments (given 1, expected 0)
- 我正在使用
- Rails 5.1.4
- Ruby 2.4.3
- 活动管理员 2.0.0.alpha
欢迎任何建议。谢谢!!
具体回答您的问题,这是一个较旧的库,更新不多,我预计不支持 lambda,但 proc{...}
应该没问题。至于为什么列表没有更新我不清楚你在这里的意图,通常 batch_action 块以 redirect_to
结尾,例如
redirect_to({action: :index}, {notice: 'Cohorts selected.'})
我在 Rails4.4.2 中解决了这个错误
wrong number of arguments (given 1, expected 0)
使用以下明显的解决方法
form_lambda = lambda do |id = nil|
# ...
end
我想在 Active Admin 中的 batch_action 中使用 lambda 时遇到问题。此错误仅在我使用 lambda 时出现,因为当我使用块时错误消失但列表未更新。这是我的代码
batch_action :set_cohorts, form: -> {{cohort: Cohort.order(:name).pluck(:name, :id)}} do |ids, inputs|
cohort = Cohort.find(inputs[:cohort])
end
form do |f|
inputs 'Sección' do
f.semantic_errors
input :cohort, as: :select, collection: -> {Cohort.order(:name).pluck(:name, :id)}
input :name
input :position
input :active, as: :radio
end
f.actions
end
错误是
wrong number of arguments (given 1, expected 0)
- 我正在使用
- Rails 5.1.4
- Ruby 2.4.3
- 活动管理员 2.0.0.alpha
欢迎任何建议。谢谢!!
具体回答您的问题,这是一个较旧的库,更新不多,我预计不支持 lambda,但 proc{...}
应该没问题。至于为什么列表没有更新我不清楚你在这里的意图,通常 batch_action 块以 redirect_to
结尾,例如
redirect_to({action: :index}, {notice: 'Cohorts selected.'})
我在 Rails4.4.2 中解决了这个错误
wrong number of arguments (given 1, expected 0)
使用以下明显的解决方法
form_lambda = lambda do |id = nil|
# ...
end