vikas
September 18, 2009, 10:23am
1
Hello,
I have following code in my view
#plan_discount
%table
%tr
%td
=“Discount Code”
%td
=text_field_tag ‘discount_code’
%td
=link_to_remote “Apply”, :update => “result”, :url => {
:action => “discount_code”}, :with => “‘discount=’+
$(discount_code).value”
#result
//Here I display processed value based on value entered in
“discount_code” //textfield
When user enter the value in discount code textfield, I process it and
display it in “result” div
My problem is that in controllers
How can I get value of “discount” which is passed as a parameter in
above link_to_remote function
def discount_code
discount_code = params[:discount] # I tried this , but get nil value
puts discount_code
render :text => discount_code
end
What is the right way to do this?
Thanks,
Vikas
vikas
September 18, 2009, 12:48pm
2
Hi Vikas G.
Either
“‘discount=’+$(‘discount_code’).value”
Or
“‘discount=’+$F(‘discount_code’)”
Sijo
vikas
September 19, 2009, 5:46am
3
Sijo Kg wrote:
Hi Vikas G.
Either
“‘discount=’+$(‘discount_code’).value”
Or
“‘discount=’+$F(‘discount_code’)”
Sijo
Thanks Sijo,
But I don’t have problem related to this.
My question is that how i access “discount” parameter value in
controller.
using discount_value = params[:discount] gives me nil.
How can i access paramter value passed in “:with”
Thanks again,
Vikas
vikas
September 19, 2009, 10:24am
4
I think the correct is :
link_to_remote “Apply”, :update => “result”, :url => {
:action => “discount_code”}, :with => “discount=$
(discount_code).value”
On Sep 19, 10:46 am, Vikas G. [email protected]
vikas
September 19, 2009, 10:48am
5
sorry it’s :
:with=>“‘discount=’+$(‘discount_code’).value” .
You missed single quote in discount_code
On Sep 19, 10:46 am, Vikas G. [email protected]
vikas
September 21, 2009, 6:50am
6
Hi Is it solved? Once more try exact this Cannot see anyother error.
link_to_remote “Apply”, :update => “result”, :url => {:action =>
“discount_code”}, :with => “‘discount=’+$(‘discount_code’).value”
And in controller params[:discount]
Sijo
vikas
September 21, 2009, 7:01am
7
Quy Doan wrote:
sorry it’s :
:with=>“‘discount=’+$(‘discount_code’).value” .
You missed single quote in discount_code
On Sep 19, 10:46�am, Vikas G. [email protected]
Thanks,
but how can i pass multiple parameters through :with option in
link_to_remote
for example
=link_to_remote “Apply”, :update => “plan_discount”, :url => { :action
=> “discount_code”}, :with=>“‘discount=’+$(‘discount_code’).value
&‘discount2=’+$(‘discount_code2’).value”
This is not working.
Where I’m doing wrong.
vikas
September 21, 2009, 7:19am
8
Hi Vikas
:with =>"‘discount=’+ escape($(‘discount_code’).value) + ‘&discount2=’ +
escape($(‘discount_code2’).value)"
Sijo
vikas
September 21, 2009, 10:04am
9
Hi
It should work.And what error you get? Also paste the code for
textfields discount_code and tariff_plan_id
Sijo
vikas
September 21, 2009, 8:59am
10
Sijo Kg wrote:
Hi Vikas
:with =>"‘discount=’+ escape($(‘discount_code’).value) + ‘&discount2=’ +
escape($(‘discount_code2’).value)"
Sijo
Hello Sijo
Thanks, but it is not working.
For only one parameter it is working fine, but not for more than one
parameter.
There is syntax error, but i tried it various ways, failed.
Following is my link_to_remote function
=link_to_remote “Apply”, :update => “plan_discount”, :url => { :action
=> “discount_code”}, :with =>"‘discount=’+
escape($(‘discount_code’).value) + ‘&tariff_plan=’ +
escape($(‘tariff_plan_id’).value)"
HTML generated from above is
Apply
vikas
September 21, 2009, 10:23am
11
Sijo Kg wrote:
Hi
It should work.And what error you get? Also paste the code for
textfields discount_code and tariff_plan_id
Sijo
“tariff_plan_id” is a redio button and “discount_code” is a textfield
%input{:type=>‘radio’, :name=>‘tariff_plan_id’,
:value=>"#{plan[‘service’][‘name’].downcase}_#{plan[‘payment_term’][‘name’].downcase}"}
=text_field_tag ‘discount_code’
=link_to_remote “Apply”, :update => “plan_discount”, :url => { :action
=> “discount_code”}, :with =>"‘discount=’+
escape($(‘discount_code’).value) + ‘&tariff_plan=’+
escape($(‘tariff_plan_id’).value)"
When I click on “Apply” link, nothing happens.
Thanks,
Vikas
vikas
September 21, 2009, 10:45am
12
H Vikas
%input{:type=>‘radio’, :name=>‘tariff_plan_id’,
:value=>"#{plan[‘service’][‘name’].downcase}_#{plan[‘payment_term’][‘name’].downcase}"}
Give also give an id to this id=>‘tariff_plan_id’
Sijo
vikas
September 21, 2009, 11:38am
13
Sijo Kg wrote:
H Vikas
%input{:type=>‘radio’, :name=>‘tariff_plan_id’,
:value=>"#{plan[‘service’][‘name’].downcase}_#{plan[‘payment_term’][‘name’].downcase}"}
Give also give an id to this id=>‘tariff_plan_id’
Sijo
Yes, by giving id to radio button it works.
But I have 5 radio_button with group “tariff_plan_id”. If i give same id
to all of them, there is problem of having same id for 5 radio buttons.
and I think this is not correct.
service[‘all_plans’].each do |plan|
%input{:type=>‘radio’, :id =>
“tariff_plan_id_#{plan[‘service’][‘name’].downcase}#{plan[‘payment_term’][‘name’].downcase}",
:name=>‘tariff_plan_id’,
:value=>"#{plan[‘service’][‘name’].downcase} #{plan[‘payment_term’][‘name’].downcase}”}
here for each plan one radio button is generated.
So another problem arises that how i know that which radio button is
selected from “tariff_plan_id” group.
if consider 5 radio buttons are there (may be increased in feature)
then I have to specify
tariff_plan_id_1
tariff_plan_id_2
tariff_plan_id_3
tariff_plan_id_4
tariff_plan_id_5
Thanks,
Vikas