1
我有一個超級基本的Rails應用程序和幾個表單。我有5個控制器,每個控制器只有1個索引視圖,未來可能更多。我想實現的是,當我輸入瀏覽器http://example.com/discover Rails自動加載發現控制器索引方法,如果我想要http://example.com/discover/city它加載發現控制器和「城市」的方法。所以,我有一個包含此此刻我的routes.rb:在Rails中創建基於控制器的通用路由
root :to => "home#index"
match '/discover/' => 'discover#index'
match '/start/' => 'start#index'
match '/blog/' => 'blog#index'
match '/help/' => 'help#index'
match '/about/' => 'about#index'
我正在尋找一種方式來寫一個通用的路由規則,即總是使用控制器查找索引方法,而對於具體的方法在控制器中,如果我添加一個輔助參數的鏈接。
這似乎很容易,但我找不到這樣做的簡單方法。