如何将html id添加到rails表单标签

如何将html id添加到rails表单标签,html,ruby-on-rails,Html,Ruby On Rails,我使用的是Rails 2.2.2,我想向form_标记生成的html表单代码添加一个id <% form_tag session_path do -%> <% end -%> 没有运气 对于\u标记可以直接指定HTML属性,如下所示: <% form_tag session_path, :id => 'elm_id', :class => 'elm_class', :style =>

我使用的是Rails 2.2.2,我想向form_标记生成的html表单代码添加一个id

<% form_tag session_path do -%>      
<% end -%>
没有运气

对于
\u标记
可以直接指定HTML属性,如下所示:

<% form_tag session_path, :id => 'elm_id', :class => 'elm_class',
                          :style => 'elm_style' do -%>
   ...
<% end -%>
“asdf”do-%>
产生

   <form action="session_path" id="asdf" method="post"><div style="margin:0;padding:0"><input name="authenticity_token" type="hidden" value="ed5c62c836d9ba47bb6f74b60e70280924f49b06" /></div>
   </form>

此代码

form_tag(:controller => "people", :action => "search", :method => "get", :class => "nifty_form")
结果如下:

<form accept-charset="UTF-8" action="/people/search?method=get&class=nifty_form" method="post">
你会得到结果的

<form accept-charset="UTF-8" action="/people/search" method="get" class="nifty_form">


这正是您想要的

在我的例子中,我需要在
{}
中添加HTML选项,以便将
id
添加到
表单标签
,如下所示:


你觉得呢?另外,只写代码的答案不是最好的——试着解释一下答案。这没问题。是的,我想:)如果你想添加类或方法或其他任何东西来形成标记,你只需要像这样打包你的控制器和操作{:控制器=>“人”,:操作=>“搜索”},然后这个结构之后的所有参数都会工作,如果它们相关的话,这真的帮了我的忙。谢谢@Kirill Warp
<% form_tag 'session_path', :id => 'asdf' do -%>      
<% end -%>
   <form action="session_path" id="asdf" method="post"><div style="margin:0;padding:0"><input name="authenticity_token" type="hidden" value="ed5c62c836d9ba47bb6f74b60e70280924f49b06" /></div>
   </form>
form_tag(:controller => "people", :action => "search", :method => "get", :class => "nifty_form")
<form accept-charset="UTF-8" action="/people/search?method=get&class=nifty_form" method="post">
form_tag({:controller => "people", :action => "search"}, :method => "get", :class => "nifty_form")
<form accept-charset="UTF-8" action="/people/search" method="get" class="nifty_form">