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
appreciated.

The form contains a field like so:
different billing
address

In my controller I reference it like so:
billing_address_hash = Hash.new()
if (params[:different_billing_info] == “1”)
billing_address_hash.merge(params[:billing_address])
else
billing_address_hash.merge(params[:customer])
# Remove customer fields not found in the billing address table
billing_address_hash.delete(‘uva_status’)
billing_address_hash.delete(‘email’)
end

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
saw:
different billing
address

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.

Thoughts?

Thanks,
Jack

how is written your form_for ?

in mine ( i have another issue… but I get the check_box value at
least)

<% 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’
unselected/selected

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?

Thorsten M. wrote:

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

I second that. That log is your best friend. I have a similiar form
where I have a whole slew of checkbox. The way you have the input named
it might be coming through as:

params[:different][:billing_info]

So in your log it might say something like:

{“different” => {“billing_info”=>“1”}}

-S

the log looks fine

“different_billing_info”=>“0”
so
params[:different_billing_info] is “0”

go on with debugging with logger.info
eg:

logger.info “FOO: #{params[:different_billing_info]}”
if (params[:different_billing_info] == “1”)
logger.info “FOO: #{params[:different_billing_info]} == ‘1’ true”
billing_address_hash.merge(params[:billing_address])
else
logger.info “FOO: #{params[:different_billing_info]} == ‘1’ false”
billing_address_hash.merge(params[:customer])

Remove customer fields not found in the billing address table

billing_address_hash.delete(‘uva_status’)
billing_address_hash.delete(‘email’)
end

just put logger.info at every step and check development.log for it’s
output

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

Parameters: {}

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:
[4;35;1mBillingAddress Update (0.000971)

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
not.

We are using

if checkbox(:id,“different_billing_info”) == “1”
puts “checkbox is checked”
else
puts “checkbox is unchecked”

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

Thanks for

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

if checkbox(different_billing_info) == “true”
puts “checkbox is checked”
else
puts “checkbox is unchecked”

try this

On 3 June 2015 at 12:29, Komala Tm [email protected] wrote:

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?

Colin