getting checkbox value

I did a search and found a reference to what I need help with but it
doesn't seem to work for me. I'm having trouble getting a value for a
checkbox and testing it in my controller. (I'm not sure what the
problem is since I have no trouble getting the other form field
values.) Some help in what I'm doing wrong would greatly be

The form contains a field like so:
<input type="checkbox" name="different_billing_info"
id="different_billing_info" value="1"
onclick="changedDifferentBillingAddress(this)"> different billing

In my controller I reference it like so:
    billing_address_hash =
    if (params[:different_billing_info] == "1")
      # Remove customer fields not found in the billing address table

I saw a prior posting to getting the checkbox value with a checked
associative array index, ie.
    if (params[:different_billing_info]['checked'] == "1")

But this seemed to make no difference. No matter what the value of the
checkbox is, the first part of the if statement above is executed.

I even tried adding a hidden field to the form based on an example I
<input type="checkbox" name="different_billing_info"
id="different_billing_info" value="1"
onclick="changedDifferentBillingAddress(this)"> different billing
<input type="hidden" name="different_billing_info" value="0"><!--
hidden billing info field used to pass a value regardless of whether
box is checked or not -->

which does in fact have the value passed be either 1 or 0 depending on
if it is checked or not. I see this in looking at the contents of the
Parameters hash.



how is written your form_for ?

in mine ( i have another issue.. but I get the check_box value at

<% form_for(:query, @query, :url => posts_url, ...

<%= f.check_box(:all_categories, :disabled => true, :onchange
=>'javascript:all_categories();') -%>

and I get it as params[:query][all_categories] => '0' or '1'

btw, my problem is having the disabled value (true/false) depending
upon the check_box value..
it seems I cannot write and evaluate a block : { @query.
all_categories == "0" } giving true or false..

I'm not using a form for; just a form_tag:
<%= form_tag("#{relative_url_root}/request/save_details") %>

And most of my form fields are created using standard HTML in the
controller's appropriate view .rhtml file.

what does development.log say about the content of
params[:different_billing_info] ? is it "1" or not?

This is more than you care to see, I'm sure:

  Parameters: {"bibl_type"=>"", "different_billing_info"=>"0",
"is_uva_person"=>"yes", "submitted_for_someone"=>"no",
"order"=>{"order_title"=>"Testing 2",
"special_instructions"=>"asdfasdf", "date_due"=>"3/20/08",
"availability"=>"Public", "entered_by"=>"", "agency_id"=>""},
"heard_about_service_other"=>"", "action"=>"save_details",
"uva_computing_id"=>"jlk4p", "department_name"=>"University of
Virginia Library", "controller"=>"request",
"customer"=>{"city"=>"Charlottesville", "heard_about_service_id"=>"1",
"country"=>"USA", "post_code"=>"22901", "uva_status"=>"Staff",
"address_1"=>"PO Box 400710, McCormick Rd., Digiital Media Lab, 301",
"address_2"=>"", "phone"=>"+1 434-924-7119", "first_name"=>"John",
"last_name"=>"Kelly", "email"=>"jlk4p@Virginia.EDU", "state"=>"VA"},
"billing_address"=>{"city"=>"Charlottesville", "country"=>"USA",
"post_code"=>"22901", "address_1"=>"PO Box 400710, McCormick Rd.,
Digiital Media Lab, 301", "address_2"=>"", "phone"=>"+1 434-924-7119",
"first_name"=>"John", "last_name"=>"Kelly", "state"=>"VA"},

The problem is that neither the contents of the customer hash nor the
billing_address hash from the form is used to write to the
billing_address table. From the log this is what's getting written to
the table, which is the existing content of the table and what was
previously in the form field before the checkbox was updated:
  e[4;35;1mBillingAddress Update (0.000971)e[0m e[0mUPDATE
`billing_addresses` SET `agency_id` = NULL, `phone` = '+1
434-244-2956', `post_code` = '22974', `country` = 'USA', `city` =
'Troy', `customer_id` = 6, `last_name` = 'Kelly', `first_name` =
'John', `address_2` = NULL, `state` = 'VA', `address_1` = '4871 Three
Chopt Rd' WHERE `id` = 6e[0m

I'm starting to think there's nothing wrong with the form parameter
value and there must be a logic problem someplace else or some other
coding issue because I always see the correct data in the params field
in the log file but that's not what the SQL is using. But my first
thought was that it was the checkbox. If I'm using the
params[:different_billing_info] is the correct way to refer to this,
then I'll move onto further debugging. I just wanted to rule this out
as the problem.

Any suggestions as to a good way for debugging code/logic that doesn't
necessarily show up in the log files?

(If you haven't figured out, I'm relatively new to RoR. Done some
reading and working on a single complex web form that will write data
to a handful of different tables.)

Can any one can give how we can check the whether checkbox is checked or

<input type="checkbox" name="different_billing_info"

We are using

if checkbox(:id,"different_billing_info") == "1"
  puts "checkbox is checked"
  puts "checkbox is unchecked"

Its is not working can you please help in Ruby-Watir scripting

Thanks for

if checkbox(different_billing_info) == "true"
 puts "checkbox is checked"

 puts "checkbox is unchecked"
try this

Thanks you guys for replying,

I have used

puts checkbox(different_billing_info).checked?

and it working thanks again folks

i dont know anything about checkbox..i have following requirement..
checkbox along with mail ids..whenever i click on first checkbox all the
mails needs to get selected..then for those mails i need to send mail in
ruby..dnt have knoweldge about rails.can anyone tell me what codes i
need to insert in controller and views in briefly

Is this a modification to an existing application or are you asking
how to write a new applications with this functionality?

You say you you don't know about rails, what experience do you have
with web development or other languages?