Andrey Drozdov Andrey Drozdov - 1 month ago 4
Ruby Question

Rails, current_page?(user_path) giving an error

I have element witch I want hide on specific pages, for example on pages located at

(there I have
. And I have div in my
it will be shown on all pages, so I want to hide it.

I thought i can do it like this:

<% unless current_page?(new_user_path) || current_page?(user_path) %>
<div>Some content</div>
<% end %>

But it will give me an error, pretty obvious: for user_show method he need an id of the user, but we are not visiting pages where variable
is present. Can you land me a help:

  1. Any possibility to get around this error? (And I don't want to assign @user variable every where and I don't want make list of all page what are allowed)

  2. Is there any other way to hide element on specific pages?


Not entirely sure what you are trying to achieve, but this is how you can guard from user not being present:

unless current_page?(new_user_path) || @user && current_page?(user_path(@user))