日付情報の扱い
rubyには日付のフォームでdate_selectという便利な機能があるのだが、現在作成中のプロジェクトの仕様的にはtext_field直打ちの方がよさそう。
以下の要領でdate型オブジェクトを作成。
view側
<% form_for :hoges, :url => {:action => 'hogehoge'} do |f| %> <%= f.text_field 'month' %> <%= f.text_field 'day' %> <% end %>
controller側
year = Date.today.year #今年の年を取得 month = params[:hoges][:month] day = params[:hoges][:day] date = Date.new(year, month.to_i, day.to_i)
getしたmonthやdayはstringなので、int型に変換
hogesにはmodelの複数形が入るらしいです。