1

ユーザーコントローラーがあります。

特定のユーザーのために、私はこのようなものを持ちたい

 example.com/a_constant_string ==> example.com/users/2

すべてのユーザーではなく、特定のユーザーだけが必要です。あなたは言うことができます

link_to 'Go to a specific user', @user
link_to 'Go to a specific user', user_path(@user)
link_to 'Go to a specific user', a_constant_string_path

同じはずです。

4

2 に答える 2

6

これもうまくいきます:

match '/a_constant_string', {controller: 'users', id: 2}

ブラウザのリダイレクトを送信しないという追加の利点 (IMO) があります。

于 2012-03-30T19:02:41.427 に答える
4

config/routes.rb でリダイレクト ルートを作成できます。

match '/a_constant_string', :to => redirect("/users/2")

これは正しいパスにリダイレクトし、URL と PATH ヘルパーを提供します:a_constant_string_patha_constant_string_url.

于 2012-03-30T18:42:19.957 に答える