2014-10-31 38 views
0

在我查看的代碼中,我有:如何在date_select中獲取某個特定月份的總天數4.1

{:controller =>'offers',:action =>'create'})do | f | %>
<%= f.date_select :startDate_get ,start_year=>2014,:end_year=>2020,:order=>[:month,:day,:year],:use_short_month=>true %> 

<%= f.date_select :endDate_get ,start_year=>2014,:end_year=>2020,:order=>[:month,:day,:year],:use_short_month=>true %> 

我是新的鐵路。

與此date_select的問題是,當我選擇任何一個月,我想看看它的days.Like,當我選擇了2月一個月,我只想看到28 days of 2014 year。 現在顯示全部天。

因此,我想驗證所有與月份的日子。

+0

你需要編寫一些jquery才能獲得這樣的功能 – Gowri 2014-10-31 07:08:15

回答

1

試試這個:

查看:

$('#start_date_2i').change(function(){ 
     var month = $(this).val() 
     $.ajax({ 
      type: 'get', 
      url: '/get_date', 
      data: {month: month}, 
      success: function(data){ 
      $('#start_date_3i option').length = data 
      } 
     }) 
     }) 

控制器:

def get_date 
    @month = params[:month] 
     @date = Time.days_in_month(@month) 
     return @date 
    end 

路線:

get '/get_date'=> 'controller#get_date' 
+0

我已經編輯了上面的代碼。jquery代碼最後一行的選項是什麼?當我嘗試這段代碼時什麼也沒有發生。 – Jack 2014-11-01 07:24:52

相關問題