# Check\_box\_tag with instance variable

**URL:** <https://www.ruby-forum.com/t/check-box-tag-with-instance-variable/140790>\
**Category:** Rails\
**Created:** [June 18, 2008, 4:12pm UTC](https://www.ruby-forum.com/t/check-box-tag-with-instance-variable/140790 "2008-06-18T16:12:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![purab](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/6de8d8/32.png) [@purab](https://www.ruby-forum.com/u/purab)\
**Post date:** [June 18, 2008, 4:12pm UTC](https://www.ruby-forum.com/t/check-box-tag-with-instance-variable/140790/1 "2008-06-18T16:12:54Z")

</div>

hi,

i am trying to use one check\_box with instance variable and trying to  
get true or false value from database table.

and also please give me solution for multiple check\_box and select all

how to feed and retrieve value and show in check box.

Thanks  
Purab

---

<div class="post-metadata">

**Author:** ![purab](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/6de8d8/32.png) [@purab](https://www.ruby-forum.com/u/purab)\
**Post date:** [June 18, 2008, 4:18pm UTC](https://www.ruby-forum.com/t/check-box-tag-with-instance-variable/140790/2 "2008-06-18T16:18:19Z")

</div>

Something like this for your first two questions?  
\<% POSSIBLE\_CATEGORIES.each do |web|%\>  
\<% if option\_checked(web) %\>  
\<%= check\_box\_tag web, ‘1’, true%\>\<%= web %\>\<% else %\>  
\<%= check\_box\_tag web %\>\<%= web %\>\<% end%\>  
\<% end %\>

Where POSSIBLE\_CATEGORIES is an array of what you want the check boxes  
to represent, ‘1’ is the value of a checked check box, and true defaults  
it to checked.

option\_checked(web) is a method in ApplicationHelper that compares the  
name of the check box (gotten from POSSIBLE\_CATEGORIES) to something  
stored in the database. You could easily modify it for the true/false  
that you want.

Sorry if I misunderstand/this doesn’t solve your problem (and there’s  
probably a better way to do this, but this works for me).

---

<div class="post-metadata">

**Author:** ![purab](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/6de8d8/32.png) [@purab](https://www.ruby-forum.com/u/purab)\
**Post date:** [June 18, 2008, 4:21pm UTC](https://www.ruby-forum.com/t/check-box-tag-with-instance-variable/140790/3 "2008-06-18T16:21:42Z")

</div>

On Wed, Jun 18, 2008 at 4:12 PM, Purab K.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> i am trying to use one check\_box with instance variable and trying to  
> get true or false value from database table.
> 
> and also please give me solution for multiple check\_box and select all
> 
> how to feed and retrieve value and show in check box.

Have a look at the check\_box helper.
