1

http://localhost:3000/pages/1からhttp://localhost:3000/homeへ、およびサイト内の他のすべてのページにルーティングする方法はありますか- http://localhost:3000/pages/4 http://localhost:3000/contact-usに自動的に?

私はこれを別の方法で行うことができます -

match "/home" => 'pages#show', :id => 1
match "/cars-for-sale" => 'pages#show', :id => 1
match "/contact-us" => 'pages#show', :id => 4

ただし、これを逆に、可能であれば自動的に行う必要があります。

4

1 に答える 1

0

おそらく、本当に必要なのはリダイレクトです:

match "/pages/1", :to => redirect("/home")
match "/pages/:id", :to => redirect("/contact-us")

順序が重要であることに注意してください-「Railsルートは、指定された順序で一致します」(http://edgeguides.rubyonrails.org/routing.htmlを参照)

于 2011-12-02T13:42:06.247 に答える