为什么我会为特定路线获得不同的链接?

时间:2013-11-24 09:50:17

标签: ruby-on-rails ruby-on-rails-3 ruby-on-rails-4

我定义了这条路线:

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"

那我错了什么?

1 个答案:

答案 0 :(得分:1)

通过使用strftime(“%d。%m。%Y”),rails将。(Dot)后的字符串作为格式,因此最好将其更改为strftime(“%d-%m-%Y” )或其他一些东西