我定义了这条路线:
get "calendar/home/(:datum)", to: 'calendar#home', as: 'calendar'
那么我的观点是home#index
我打电话:
<%= link_to 'Kalender', calendar_path(Date.today.strftime("%d.%m.%Y")) %>
这链接到:
http://localhost:3000/calendar/home?datum=24.11.2013
所以现在calender#home
调用的视图中的奇怪之处是:
def home
@date = Date.parse(params[:datum])
@monday = @date.beginning_of_week
...
<%= link_to "Montag", calendar_path(@monday.strftime("%d.%m.%Y")), :class => "btn btn-primary" %>
以某种方式链接到:Whitout ?datum=
http://localhost:3000/calendar/home/18.11.2013
当我点击此链接时,我收到错误消息:
No route matches [GET] "/calendar/home/18.11.2013"
那我错了什么?
答案 0 :(得分:1)
通过使用strftime(“%d。%m。%Y”),rails将。(Dot)后的字符串作为格式,因此最好将其更改为strftime(“%d-%m-%Y” )或其他一些东西