【发布时间】:2011-01-04 19:20:41
【问题描述】:
我有一个基本控制器,其中包含代表静态页面的命名操作:
class YourTripController < ApplicationController
def when_to_visit
end
def booking_a_trip
end
...
end
我想要一个命名路由来访问这些操作,例如:
your_trip_path(:when_to_visit)
your_trip_path(:booking_a_trip)
看起来很简单吧?但我也想让 URL 使用破折号而不是下划线来生成路径:
example.com/your-trip/when-to-visit example.com/your-trip/booking-a-trip
鉴于这些限制,我的路线是什么样的?
我尝试了很多方法,这是迄今为止我最接近的方法:
controller :your_trip, :path => 'your-trip', :as => :your_trip do
get "when_to_visit", :path => 'when-to-visit'
get "booking_a_trip", :path => 'booking-a-trip'
end
这会正确地将我引导到正确的操作,但使用诸如 your_trip_path(:when_to_visit) 之类的 url 助手会导致:
没有路线匹配 {:action=>"when_to_visit", :controller=>"your_trip"}
【问题讨论】:
标签: ruby-on-rails routing ruby-on-rails-3