1
我的問題是關於在軌道應用程序的路線中使用日期過濾器,在我準備好具有與routes.rb文件中的日期模式相匹配的規則的時刻,它看起來像這樣的:Rails路線與日期
match "itineraries/:day/:month/:year" => "itineraries#index",
:constraints => { :year => /\d{4}/, :month => /\d{2}/, :day => /\d{2}/ }
match "itineraries/new/:day/:month/:year" => "itineraries#new",
:constraints => { :year => /\d{4}/, :month => /\d{2}/, :day => /\d{2}/ }
resources :itineraries
match '/:controller(/:action(/:id))'
root :to => "itineraries#index"
那場比賽例如/行程/ 01/01/2011,問題是當我生成資源的路徑,例如,itineraries_path(:年=> 2011年:月=> 1 ,:天=> 1)產生:
/行程天= 1 &一個月= 1個& year2011
代替
/行程/ 01/01/2011
有沒有把資源映射內的匹配規則的方法嗎?
但是如果你想獲得'itineraries/01/01/1998',你應該調用'itineraries_date_path(「01」,「01」,1998)' – 2011-06-11 19:58:58
'限制:{year:/ \ d {4} /,month :/ \ d {1,2} /,day:/ \ d {1,2} /}'應該解決這個問題。 – 2011-06-11 21:00:15
優秀,這就是訣竅 – ramontiveros 2011-06-13 03:49:16