Reputation: 6653
I'm trying to add a hidden input with a predetermined "value" in it
<%= f.input :step, :as => :hidden, :input_html => { :value => "3" } %>
In this instance I'm using hidden inputs to determined which form on a page with more than one form is submitted.
This looks to display correctly in the html but submitting the form produces this error
unknown attribute: step
Upvotes: 3
Views: 4668
Reputation: 20724
If the field isn't on your model you have to choices. You can simply use the hidden_field_tag like in the following:
<%= hidden_field_tag 'step' %>
Or you can add a virtual attribute to your model and use the code you've shown. Like in the following:
class Model
attr_accessor :step
end
I can't say which I would use because I don't what you're trying to do with the step field.
Upvotes: 4