سؤال

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

هل كانت مفيدة؟

نصائح أخرى

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}") %>
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top