简体   繁体   English

Rails如何以编程方式从表单获取HTML ID

[英]Rails how to programatically get html id from form

Say I have a Rails form like the following 说我有一个如下的Rails表单

 <% form_for @model do |f| %>
   <%= f.label :column %>
   <%= f.check_box :column %>
 <% end %>

Is there a way I can get the html id that will be generated for the 'column' check box? 有没有一种方法可以获取将为“列”复选框生成的html id? What would be great is if there was a way to add in 最好的是,如果有一种添加方法

  <%= f.observe_field :column, options %>

Anyone know how to add this to FormBuilder? 有人知道如何将其添加到FormBuilder吗?

For generating an element's id programatically, see this . 要以编程方式生成元素的ID,请参见this As it seems, there is no easy way out. 看起来,没有简单的出路。

You could add this to FormBuilder by wrapping up certain field tags. 您可以通过包装某些字段标签将其添加到FormBuilder中。 See for example this . 例如参见this

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM