0

So I have a program where a user can create events, and there will be multiple events. So the events index page looks like "/events" on the browser, and it's subdirectory show pages looks like "/events/1 /events/2 ... etc".

In my layout page I am checking the current page in order to decide what background color the page will have. This is easy for the events index page; I just check if it is that page via the command:

if current_page?(events_path) ...

But I want to check if the current page is a specific 'show' page of the index (a standard scaffold generated page). How would I do that? This is my attempt, I am confused about how the routing would work in this case:

if current_page?(events_id_path) ...
ifma
  • 3,673
  • 4
  • 26
  • 38
  • You should try `action_name == "show"`. You can add another condition, with `controller_name == "YOURCONTROLLERNAME"` – Amit Badheka Jul 13 '15 at 14:15

1 Answers1

1

So simple, try the below code

if current_page?(event_path(@event))

Assuming you have @event defined in your controller.

or

if current_page?(controller: 'events', action: 'show', :id => id)

For more Info, see this API Doc

Pavan
  • 33,316
  • 7
  • 50
  • 76
  • So I am not sure if this would work, because I am checking the current page at the layout.html.erb file itself of the layouts directory, and I only declare the @event at the events controller. But I will try, thanks. – ifma Jul 13 '15 at 14:12
  • worked without the id, thanks very much, I was trying something similar except I had action as method, my mistake – ifma Jul 13 '15 at 14:43