你正在做一些AJAX調用手段,您必須調用單選按鈕變化
所以我假設了AJAX的一部分,你已經使用單選按鈕和單選按鈕的名稱做了是'choose_product'
您可以在視圖中添加隱藏字段,您可以在其中存儲當前日期。
<div id='parentDiv'>
<%= hidden_field_tag 'current_date', Time.now.strftime('%d-%m-%Y') %>
Your radio button code
</div>
在javascript中添加以下代碼。這只是一個不完整的解決方案。
$(document).ready(function(){
var showProducts = function(){
$("#parentDiv").on('click', "input[name='choose_product']", function(){
var ajax_url = 'localhost:3000/dashboard/catalog';
var url_param = '';
switch($(this).val()){
case 'creation_date':
var param_date = $('#current_date').val();
url_param = '?name=radio&date_creation=' + param_date;
break;
case 'name':
// Your code goes here
default:
//Your code goes here
}
// Here you will get the modified url dynamically
ajax_url += url_param
$.ajax({
url: ajax_url,
// your code goes here
});
});
}
showProducts();
});
如果用ajax(通過執行'window.location.href ='new/url'')更改URL,頁面將重新加載。您需要在'#'之後向URL添加參數,因此您的URL將如下所示:'localhost:3000/dashboard/catalog#name = radio&date_creation = 23-06-2013' – MrYoshiji