0
我用datetimepicker.js和bootstrap使用ransack gem來執行日期範圍搜索。查詢是可以的,但是當模板被渲染時,它不會在視圖中保留我之前選擇的日期值。rails datetimepicker從輸入中選擇的清除日期
這是響應URL:
這是在控制器指數法:
def index
@ransack = Multicast::Batch.includes(:cost_centre).where(customer_id: current_customer_id || '---')
.order('scheduled_to DESC, created_at DESC')
.search(params[:q])
@batches = @ransack.result.page(params[:page]||1).per(10).decorate
end
這是指數的HTML代碼:
.form-group
= f.label :created_at_gteq, " FROM: "
.input-group.date.calendar
= f.text_field :created_at_gteq, class: "form-control"
span.input-group-addon
span.glyphicon.glyphicon-calendar
= f.label :created_at_lteq, " TO: "
|
.input-group.date.calendar
= f.text_field :created_at_lteq, class: "form-control"
span.input-group-addon
span.glyphicon.glyphicon-calendar
這是datetimepicker功能:
$(function() {
$('.calendar').datetimepicker();
});