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:
<input type="checkbox" name="different_billing_info"
id="different_billing_info" value="1"
onclick="changedDifferentBillingAddress(this)"> 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:
<input type="checkbox" name="different_billing_info"
id="different_billing_info" value="1"
onclick="changedDifferentBillingAddress(this)"> different billing
address
<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.
Thoughts?
Thanks,
Jack
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
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..
On 14 fév, 18:18, Jack <jl...-4Ng6DfrEGID2fBVCVOL8/A@public.gmane.org>
wrote:> 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:
> <input type="checkbox" name="different_billing_info"
> id="different_billing_info" value="1"
> onclick="changedDifferentBillingAddress(this)"> 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:
> <input type="checkbox" name="different_billing_info"
> id="different_billing_info" value="1"
> onclick="changedDifferentBillingAddress(this)"> different
billing
> address
> <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.
>
> Thoughts?
>
> Thanks,
> Jack
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
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.
On Feb 14, 12:28 pm, Erwin <yves_duf...-ee4meeAH724@public.gmane.org>
wrote:> how is written your form_for ?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
what does development.log say about the content of params[:different_billing_info] ? is it "1" or not? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thorsten Mueller 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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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",
"materialsRemovedItemCount"=>"0",
"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-utW8kV9oO443r0Ub5QXD9Q@public.gmane.org",
"state"=>"VA"},
"materialsItemCount"=>"0",
"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"},
"for_uva_computing_id"=>""}
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) [0m [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` = 6 [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.)
On Feb 14, 12:41 pm, Thorsten Mueller <rails-mailing-l...@andreas-
s.net> wrote:> what does development.log say about the content of
> params[:different_billing_info] ? is it "1" or not?
> --
> Posted viahttp://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
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
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Can any one can give how we can check the whether checkbox is checked or not. <input type="checkbox" name="different_billing_info" id="different_billing_info"> 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 -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
if checkbox(different_billing_info) == "true" puts "checkbox is checked" else puts "checkbox is unchecked" try this -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Thanks you guys for replying, I have used puts checkbox(different_billing_info).checked? and it working thanks again folks -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.