how to add html id to rails form_tag

前端 未结 4 1157
北荒
北荒 2021-01-31 13:36

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 -%&g         


        
4条回答
  •  感情败类
    2021-01-31 14:01

    For _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 _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 -%>
    

提交回复
热议问题