Reputation: 43
I have a select_tag which is displaying all the users
from my db, when selected is sending the user to users/1..n
.
How can I check if the users is on page users/1
or users/2
. I need this because I want to display different things if the user is on those pages.
A solution that I thought about is to render a different layout
but it seems to much work to only hide or display 5 divs.
Thank you
Upvotes: 0
Views: 2881
Reputation: 7779
You can use the helper current_page?
http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-current_page-3F
Upvotes: 6
Reputation: 10997
You can use request.original_url
to return the path that's been requested. from the docs:
# get "/articles?page=2"
request.original_url # => "http://www.example.com/articles?page=2"
you could then do something like this:
controller:
@user = current_user
@current_page = request.original_url
view:
<%= do [this stuff] if @current_page.include?("users/x") %>
if you want to check if the user is on their own page you could try this:
<%= do [my own page stuff] if @current_page.include?("users/#{@user.id}") %>
Upvotes: 0