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

Inaccessible
  • 1,560
  • 3
  • 18
  • 42
  • 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. – sjain Feb 26 '13 at 09:22
  • @ Saurabh Jain thanks for this checking. but params[:depart] also shows nil. – Inaccessible Feb 26 '13 at 09:41
  • Check my answer below and see what it gives for both. – sjain Feb 26 '13 at 09: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' – Inaccessible Feb 26 '13 at 09:54

1 Answers1

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>
sjain
  • 23,126
  • 28
  • 107
  • 185
  • 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]`. – sjain Feb 26 '13 at 09:53
  • @depart=params[:depart] @return=params[:return_date] this is my code in controller – Inaccessible Feb 26 '13 at 09:57
  • if it is possible to pass Js variable using link_to in rails 3 pls suggest me – Inaccessible Feb 26 '13 at 10:23
  • http://stackoverflow.com/questions/5875448/rails3-how-to-send-javascript-variable-to-a-controllers-action-with-the-link – sjain Feb 26 '13 at 10:28