2016-10-12 7 views
1

私はnoobです。追加のパラメータを使用してredirect_to

redirect_to users_url, notice: 'Succeed.' 

<p id="notice"><%= notice %></p> 

それから私はmessageを追加し、それが失敗しました:

redirect_to users_url, notice: 'Succeed.', message: 'test' 

<p id="notice"><%= notice %></p> 
<h1><%= params[:message] %></h1> # no result 
<h1><%= message %></h1> # name error 

users_urlusers_pathとの違いは何ですか?

+0

[パスのパラメータを渡す\ _to](http://stackoverflow.com/questions/1430247/passing-parameters-in-rails-redirect-to) – CDub

答えて

3

あなたは_url_path方法でそれを渡したいでしょう:「成功」

redirect_to users_url(message: 'test'), notice: 'Succeed.' 

これがためにフラッシュ通知を設定し、/usersの絶対パスにリダイレクトされますmessageの追加パラメータを「test」に設定してください。 _urlルートへの絶対URLを返すのに対し、ルートへの相対パスを返し_pathあなたの2番目の質問に答える

users_url # => http://www.example.com/users 
users_path # => /users 

_urlは、例えば、電子メールや生きるリンクについては、便利ですあなたのアプリの外に。

関連する問題