0
<script> var depart_date='11 February 2013';
         var depart_date='21 February 2013';


    jQuery.ajax({

data: { depart: depart_date, return_date: return_date},
    type: 'post',
  url: "/payment/create",

});

This is my ajax call.

In terminal it's value getting as {"depart"=>"11 February 2013", "return_date"=>"21 February 2013"}

But in controller params[:depart] & params[:return_date] shows as nil value.

Don't know where i am doing mistake..

4
  • If you are getting values in terminal then you are all right. The only thing is: its params[:return_date] and not params[:return]. The second thing is, you ended the script before ajax function. Commented Feb 26, 2013 at 9:22
  • @ Saurabh Jain thanks for this checking. but params[:depart] also shows nil. Commented Feb 26, 2013 at 9:41
  • Check my answer below and see what it gives for both. Commented Feb 26, 2013 at 9:43
  • in terminal it is passing as {"depart"=>"11 February 2013", "return_date"=>"21 February 2013"}.but when i try to get in controller as params[:depart] &params[:return_date].both returns 'nil' Commented Feb 26, 2013 at 9:54

1 Answer 1

1

Change depart_date to return_date and end the script at the end as:

<script> 

   var depart_date='11 February 2013';
   var return_date='21 February 2013';

        jQuery.ajax({

    data: { depart: depart_date, return_date: return_date},
        type: 'post',
      url: "/payment/create",

    });

    </script>
Sign up to request clarification or add additional context in comments.

4 Comments

Make sure that you defined your params[:depart] and params[:return_date] in your create method of payments controller. Also check what is the value for params[:return_date].
@depart=params[:depart] @return=params[:return_date] this is my code in controller
if it is possible to pass Js variable using link_to in rails 3 pls suggest me

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.