Hey, How can I pass a boolean value in a form to a controller without the user being able to see or edit it? I'm assuming hidden_field is used for this, but how can I then assign a value to the variable?
Thanks for the help -Pat
Hey, How can I pass a boolean value in a form to a controller without the user being able to see or edit it? I'm assuming hidden_field is used for this, but how can I then assign a value to the variable?
Thanks for the help -Pat
Pat,
I am slightly confused by what you mean with the 'but how can I then assign a value to the variable', but I'll give this a go.
First off, you are correct in the hidden_field bit.
<%= hidden_field_tag 'some_name', true %>
or, alternatively
<%= hidden_field_tag 'some_name', false %>
You get the point with that, I'm sure.
From there, in your controller, when the form is submitted you would get the value of that field like so:
some_boolean = params[:some_name]
Obviously variable names would be different, but that's the general gist of it all.
Good luck!