# Howto: Check\_box with a variable (no model)

**URL:** <https://www.ruby-forum.com/t/howto-check-box-with-a-variable-no-model/98949>\
**Category:** Rails\
**Created:** [July 19, 2006, 7:49am UTC](https://www.ruby-forum.com/t/howto-check-box-with-a-variable-no-model/98949 "2006-07-19T07:49:08Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ptremblett](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/dc4da7/32.png) [@ptremblett](https://www.ruby-forum.com/u/ptremblett)\
**Post date:** [July 19, 2006, 7:49am UTC](https://www.ruby-forum.com/t/howto-check-box-with-a-variable-no-model/98949/1 "2006-07-19T07:49:08Z")

</div>

Hi,

I would like to put a checkbox on a form where the input field is a  
variable rather than a field in a model.

The normal way (with a model) would be:

\<%= check\_box(‘client’, ‘accept’, {}, “1”, “0”) %\>

But since accept is a variable @accept and model client will not be  
there, how do I make a check box work?

Regards,

Paul

---

<div class="post-metadata">

**Author:** ![ptremblett](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/dc4da7/32.png) [@ptremblett](https://www.ruby-forum.com/u/ptremblett)\
**Post date:** [July 19, 2006, 9:21am UTC](https://www.ruby-forum.com/t/howto-check-box-with-a-variable-no-model/98949/2 "2006-07-19T09:21:32Z")

</div>

Paul Jonathan T. wrote:

> there, how do I make a check box work?  
> Generally, you would use the same helper, but with \_tag appended. So in  
> this case, check\_box\_tag. It is detailed here :  
> [Peak Obsession](http://api.rubyonrails.com/classes/ActionView/Helpers/FormTagHelper.html#M000500)  
> (well, the documentation is pretty sparse on this particular helper -  
> but you should be able to figure it out.

Regards,  
Henning K.  
[Railsfoundry.com](http://Railsfoundry.com)

---

<div class="post-metadata">

**Author:** ![ptremblett](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/dc4da7/32.png) [@ptremblett](https://www.ruby-forum.com/u/ptremblett)\
**Post date:** [July 19, 2006, 2:01pm UTC](https://www.ruby-forum.com/t/howto-check-box-with-a-variable-no-model/98949/3 "2006-07-19T14:01:35Z")

</div>

Paul Jonathan T. wrote:

> Hi,
> 
> I would like to put a checkbox on a form where the input field is a  
> variable rather than a field in a model.
> 
> The normal way (with a model) would be:
> 
> \<%= check\_box(‘client’, ‘accept’, {}, “1”, “0”) %\>
> 
> But since accept is a variable @accept and model client will not be  
> there, how do I make a check box work?
> 
> Regards,
> 
> Paul

Hi Pail, I hope this helps but this is how we did it:

\<% $findrecord.each do |$findrecord| %\>  
\<%  
$array = TableRecords.find\_by\_sql([“select \* from table\_records where id  
= ?”, $findrecord.id])

$recordrow = $array[0]  
$recordid = $recordrow.id.to\_s  
$recordemail = $recordrow.email%\>  
  
\<%= check\_box (“checker”, “#{$recordid}”, {}, “yes”, “no”)  
%\>&nbsp;&nbsp;\<%=$recordemail%\>  
\<% end %\>

thanks,

Bing

---

<div class="post-metadata">

**Author:** ![ptremblett](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/dc4da7/32.png) [@ptremblett](https://www.ruby-forum.com/u/ptremblett)\
**Post date:** [July 19, 2006, 2:06pm UTC](https://www.ruby-forum.com/t/howto-check-box-with-a-variable-no-model/98949/4 "2006-07-19T14:06:02Z")

</div>

Oops,

obviously I wasn’t reading the premise quite clearly, well, just have  
the check\_box make a loop as many times as you want and you can pass a  
variable into the second field on the check\_box helper.

I hope that was of any help.

thanks,

Bing

---

<div class="post-metadata">

**Author:** ![ptremblett](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/dc4da7/32.png) [@ptremblett](https://www.ruby-forum.com/u/ptremblett)\
**Post date:** [July 20, 2006, 12:33am UTC](https://www.ruby-forum.com/t/howto-check-box-with-a-variable-no-model/98949/5 "2006-07-20T00:33:14Z")

</div>

Bing T. wrote:

> Oops,
> 
> obviously I wasn’t reading the premise quite clearly, well, just have  
> the check\_box make a loop as many times as you want and you can pass a  
> variable into the second field on the check\_box helper.

I think using check\_box\_tag would be a LOT easier, but that is just me  
🙂

–  
Henning K.  
Rails Foundry  
[http://railsfoundry.com/](http://railsfoundry.com/)

---

<div class="post-metadata">

**Author:** ![ptremblett](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/dc4da7/32.png) [@ptremblett](https://www.ruby-forum.com/u/ptremblett)\
**Post date:** [July 20, 2006, 1:15am UTC](https://www.ruby-forum.com/t/howto-check-box-with-a-variable-no-model/98949/6 "2006-07-20T01:15:28Z")

</div>

Hi,

Thanks for the help. I used check\_box\_tag and it worked just fine.

Regards,

Paul

---

<div class="post-metadata">

**Author:** ![ptremblett](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/dc4da7/32.png) [@ptremblett](https://www.ruby-forum.com/u/ptremblett)\
**Post date:** [July 20, 2006, 2:50am UTC](https://www.ruby-forum.com/t/howto-check-box-with-a-variable-no-model/98949/7 "2006-07-20T02:50:38Z")

</div>

On 7/20/06, Paul Jonathan T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Thanks for the help. I used check\_box\_tag and it worked just fine.

When I need a user to tick a “terms & conditions” checkbox, I use a  
check\_box helper but in the model do ‘validates\_acceptance\_of :terms’  
even though terms is not a field in the database.

I realise you don’t have a corresponding model, but thought I’d throw  
this in.
