views:

507

answers:

1

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

+1  A: 

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!

Eric
sorry I wasn't very clear, I had a mysql field that was susposed to take a boolean value and depending on the form I wanted to assign it true or false. I ended up using a radio button that wasn't rendered on the page that had the correct value to pass into mysql.Thanks for the help though.
Pat R