1

Here's the route:

get "search(/:search)", to: "posts#index", as: :search

Now if I'm at /search/somethingsomething and the view is:

- if current_page?(search_path)
  = (do something)

then that something isn't being done. If I remove the parenthesis around :search, however (i.e. get "search/:search" ...), then it works. What gives?

Arif
  • 712
  • 11
  • 20

2 Answers2

1

You can use this condition

current_page?(controller: 'posts', action: 'index')

when you use search_path in condition it generated without optional parameters

Michael Malov
  • 1,877
  • 1
  • 14
  • 20
  • That didn't work. I solved it later though, by replacing the condition with `- if current_page?("/search/#{params[:search]}")` – Arif Aug 08 '16 at 07:38
0

Never mind. Solved it by replacing the condition with:

- if current_page?("/search/#{params[:search]}")
Arif
  • 712
  • 11
  • 20