6

How to assign specific id and name to hidden_field_tag ?

Like this,

hidden_field_tag(:id => "page_no",:name => "page", :value => "1" )

Any Idea!

krunal shah
  • 16,089
  • 25
  • 97
  • 143

3 Answers3

19
hidden_field_tag("page_name", "1", :id => "page_no")

per http://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html#method-i-hidden_field_tag

Mike Lewis
  • 63,433
  • 20
  • 141
  • 111
9

It takes hidden_field_tag(name, value = nil, options = {})

So the third parameter is for options.

hidden_field_tag("page", "1", {:id => "page_no"}) would set name to "page", value to "1" and id to "page_no"

lebreeze
  • 5,094
  • 26
  • 34
2

You have to pass first parameter as name, and second as value. Also, you can override the name of the parameters like this.

  <%=hidden_field_tag :param_name, 'param_value', {:id => 'ashish_id', :name => 'another_name'}%>
Ashish
  • 5,723
  • 2
  • 24
  • 25