[英]How to dynamically get value of input fields in ruby active admin form
[英]How do I get the value of a form.input in active admin (ruby on rails)
我正在使用管理框架“活动管理员”来构建 RubyOnRails 应用程序。 我的表单中有一个下拉菜单,如下所示:
form do |f|
f.inputs do
f.input :art, as: :select, :include_blank => "Bitte wählen!", label: 'art', :collection => ["Fachobjekt", "Gruppe", "Externes Dokument"]
end
f.actions
end
现在在我的控制器中,我想检查选定的值。 我试过:
controller do
after_save :update_object
def update_object(guid)
if params[:art].values == 'Fachobjekt'
# do stuff
end
end
end
我在下拉列表中选择了 'Fachobjekt' 但我得到了NoMethodeError "undefined method 'values' for nil:NilClass"
,所以params[:art]
为空。
我的问题是:获取 f.input-field 的选定值的正确语法是什么? 我很感激任何提示!
[:root_tables] 是模型名称。 我把它放在 [:art] 之前,就像 params[:root_tables][:art] 但同样的错误。
放一个
raise params.inspect
就在之前
if params[:art]
线。 您应该能够识别发布的信息在参数中的位置。
感谢您的所有提示! 特别是使用 binding.pry 进行调试的提示帮助了我。 我现在使用 f.select 而不是 f.input:
form do |f|
f.inputs do
f.select :art, ["Fachobjekt", "Gruppe", "Externes Dokument"], :prompt => 'Bitte wählen! '
end
f.actions
end
对于选择 params[:root_table][:art] 正在工作:
controller do
after_save :update_object
def update_object(guid)
if params[:root_table][:art] == 'Fachobjekt'
# do stuff
end
end
end
当我使用 f.input 时,[:art] 在执行 binding.pry 或 raise params.inspect 时甚至没有出现。 使用 f.select 确实如此。 但是,至少它现在可以工作,所以谢谢!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.