2011-06-16 117 views

回答

1

隨着你擁有它,你就必須設置此明確

Date.civil(params[:date][:year].to_i, params[:date][:month].to_i, params[:date][:day].to_i) 

來獲得日期的方式。

但是,更簡單的方法是更改​​選擇。

<%= select_date :model, :date %> 

<%= f.select_date :date %> 

取決於你如何表達形式。

然後,只需添加一個before_create方法模型設置當前日期:

before_create :start_with_todays_date 

def start_with_todays_date 
    self.date = Date.today 
end 
相關問題