Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby on Rails Boolean Form

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

like image 732
Pat R Avatar asked Apr 28 '26 16:04

Pat R


1 Answers

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!

like image 167
Eric Avatar answered Apr 30 '26 07:04

Eric



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!