get_class_swimming_students_path('2013-01-01', '2013-02-02')
在 Rails 中,URL 参数按照它们传递的精确顺序映射到路由器。考虑以下几点:
# rake routes
my_route GET /my_route/:first_param/:second_param/:third_param(.:format)
# my_view.html.erb
<%= link_to('My Route', my_route_path('first_param', 'second_param', 'third_param') %>
#=> <a href="/my_route/first_param/second_param/third_param">My Route</a>
还要考虑以下情况,其中foo 和bar 是位于动态参数之间的静态参数:
# rake routes
my_route GET /my_route/:first_param/foo/:second_param/bar/:third_param(.:format)
# my_view.html.erb
<%= link_to('My Route', my_route_path('first_param', 'second_param', 'third_param') %>
#=> <a href="/my_route/first_param/foo/second_param/bar/third_param">My Route</a>
在最后一个示例中,参数将按照传递它们的顺序显示为 URL 参数,但不一定在相同的顺序中。
编辑:
下面的语法等价于第一个sn-p。主要区别在于它接受参数作为命名参数,而不是按照它们传递的顺序:
get_class_swimming_students_path(:start_date => '2013-01-01', :end_date => '2013-02-02')