[英]Rails Action View Form Helper pass options hash to create element
Given a hash of properties for a text_field to be made in HAML: 给定要在HAML中创建的text_field的属性的哈希值:
entry = {class: "form-control", disabled: true, id: :foobar}
How can I do this: 我怎样才能做到这一点:
%dd!= f.send(:text_field, entry[:id], class: entry[:class], disabled: entry[:disabled])
But flexible? 但是灵活吗? (So don't need placeholders, just a hash).
(因此不需要占位符,只需一个哈希即可)。 Have looked at simple form docs and action view form helper docs and found
input_html
, but that's not working in this manner. 查看了简单的表单文档和操作视图表单帮助文档,并找到了
input_html
,但是这种方式不起作用。
The f.send
is obligatory, as :text_field
can be anything. f.send
是必须的,因为:text_field
可以是任何东西。 Would prefer not to use eval 宁愿不使用eval
text_field
takes: text_field
需要:
text_field(attribute_name, input_html_options)
Does 是否
f.text_field(entry[:id], entry)
not work? 不行?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.