Reputation: 927
I am a noob.
redirect_to users_url, notice: 'Succeed.'
<p id="notice"><%= notice %></p>
Then I add a message
and it failed:
redirect_to users_url, notice: 'Succeed.', message: 'test'
<p id="notice"><%= notice %></p>
<h1><%= params[:message] %></h1> # no result
<h1><%= message %></h1> # name error
What's the differences between users_url
and users_path
?
Upvotes: 2
Views: 5983
Reputation: 13354
You'll want to pass it in the _url
or _path
method:
redirect_to users_url(message: 'test'), notice: 'Succeed.'
This will redirect to the absolute path for /users
, setting the flash notice to "Succeed." with an additional parameter of message
set to "test".
To answer your second question, _path
returns a relative path to the route whereas _url
returns an absolute URL to the route:
users_url # => http://www.example.com/users
users_path # => /users
_url
is useful, for example, in emails or for links that will live outside your app.
Upvotes: 4