Andrey Drozdov Andrey Drozdov - 1 year ago 71
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?

Answer Source

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))
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download