Skip to content

Hidden fields in rails (or: sometimes rails sucks)

Well, in general, ruby on rails is a powerful tool for developing web applications. But sometimes it really sucks, because of inconsistencies in the API. I tried to add a hidden field to a form_for. A hidden field for form_tag works like:

<%= hidden_field_tag :my_variable, 'my_value' %>

So for form_for forms, I expect (similar to text_field etc.):

<%= f.hidden_field :my_variable, 'my_value' %>

But this solution just produces some weired error. Reading the API documentation [1], my code seems to be correct. No hint whatsoever to the solution:

<%= f.hidden_field :my_variable, :value => 'my_value' %>