Howto: Check_box with a variable (no model)

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

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 :
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

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”)
%>  <%=$recordemail%>
<% end %>

thanks,

Bing

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

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
:slight_smile:


Henning K.
Rails Foundry
http://railsfoundry.com/

Hi,

Thanks for the help. I used check_box_tag and it worked just fine.

Regards,

Paul

On 7/20/06, Paul Jonathan T. [email protected] 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.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs