B
B
bismoney2015-10-22 20:02:05
Ruby on Rails
bismoney, 2015-10-22 20:02:05

Ruby on Rails checkbox?

Hello friends.
How to organize a checkbox whose value will be stored in the database?
UPD
For example, when creating a post / new
, the "Show" checkbox will be used.
By default, it will be set, but it can be removed.
Let's say two blocks will be displayed on the main page.
One will include posts in which the checkbox is enabled, and the second in which the checkbox is unchecked...
Sorry for the crooked Russian, and for the noobsto, I'm just getting used to RoR, don't be angry :) I'm
interested in how to make the checkbox write the value 0/1 in base when adding or editing a post.
And also interested in how to filter posts by checkbox on / off ..
Thank you :)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
CapeRatel, 2015-10-22
@bismoney

In the database, you make a boolean field (boolean is true or false (as you say 0/1))
migration is like this:
t.boolean : field_name, default: false

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question