Ruby on Rails Boolean Form

How to transfer a logical value in a form to a controller without the ability to see or edit it? I assume hidden_field is used for this, but how can I assign a value to a variable?

Thanks for the help -Pat

+3
source share
1 answer

Pat

I'm a little confused about what you mean by “but how can I assign a value to a variable”, but I will give it.

First you are right in the hidden_field cue ball.

<%= hidden_field_tag 'some_name', true %>

or alternatively

<%= hidden_field_tag 'some_name', false %>

You understand that I am sure.

From there, in your controller, when the form is submitted, you will receive the value of this field as follows:

some_boolean = params[:some_name]

Obviously, the variable names will be different, but the general meaning of everything.

Good luck

+4

Source: https://habr.com/ru/post/1717766/


All Articles