如何将html id添加到rails form_tag [英] how to add html id to rails form_tag

查看:107
本文介绍了如何将html id添加到rails form_tag的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是Rails 2.2.2,我想向由form_tag生成的html表单代码添加一个id。

 <%form_tag session_path do  - %> 
<%end - %>

目前产生:

 < form action =/ sessionmethod =post> 
< / form>

希望产生:

 < form id =login_formaction =/ sessionmethod =post> 
< / form>

api 实际上没有任何帮助,我尝试添加

 :html => {:id => 'login_form'} 

没有运气。对于< element> _tag ,您可以直接指定HTML属性,如下:

 <%form_tag session_path,:id => 'elm_id',:class => 'elm_class',
:style => 'elm_style'do - %>
...
<%end - %>

它用于< element> _ 远程 _tag 构造您需要将:html map:

 <%form_tag form_remote_tag:url => session_path,:html => {
:id => 'elm_id',:class => 'elm_class',
:style => 'elm_style'} do - %>
...
<%end - %>


I am using Rails 2.2.2 and I would like to add an id to the html form code generated by the form_tag.

<% form_tag session_path do -%>      
<% end -%>

Currently produces:

<form action="/session" method="post">
</form>

Would like it to produce:

<form id="login_form" action="/session" method="post">
</form>

The api isn't really any help and I've tried adding various combinations of

:html => {:id => 'login_form'}

with no luck.

解决方案

For <element>_tag you specify HTML attributes directly, as follows:

<% form_tag session_path, :id => 'elm_id', :class => 'elm_class',
                          :style => 'elm_style' do -%>
   ...
<% end -%>

It is for <element>_remote_tag constructs that you need to move the HTML attributes inside a :html map:

<% form_tag form_remote_tag :url => session_path, :html => {
                            :id => 'elm_id', :class => 'elm_class',
                            :style => 'elm_style' } do -%>
   ...
<% end -%>

这篇关于如何将html id添加到rails form_tag的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆