Closed philipgiuliani closed 7 years ago
As breadcrumb second argument you can use anything that Rails accepts including parameterized hash {controller: :publications, action: :index}
?
Wow thanks. It really worked.
Idea how to solve it if its namespaced?
I would try again Rails conventions, so as controller parameter do controller: '/admin/publications'
or similar. The leading slash will ensure that the url gets resolved as Admin::Publications
. Does it work?
Ok i found the problem. You are currently calling url_for(controller: ...., action: ....) before passing it to current_page?
.
If i have:
# routes.rb
root "publications#index"
resources :publications, only: :index
and call url_for the following is returned:
url_for controller: "/publisher/publications", action: :index
# => http://localhost:3000/de/publisher
The Problem
When i go to http://localhost:3000/de/publisher
everything is fine, and it is highlighted. But when i go to http://localhost:3000/de/publisher/publications
, current_page?
returns false with this URL.
Would be cool if you could pass the hash directly to current_page?
. I think that should be the solution :) Thanks and sorry for distubing!
The issue also causes the folowing problem. The only thing i left away is the string at the end thats created by to_param
url_for(...)
# => http://localhost:3000/de/publisher/publications/1-dolomiten/magazines/73-ausgabe-3-2014
current_page?("http://localhost:3000/de/publisher/publications/1-dolomiten/magazines/73")
# => false
Ok, understood. Do you want to take a stab at it and submit pull request? I will happily review and merge - provided there are tests demonstrating the issue :smile:
It's been a long time since this issue has been posted - sorry!
However, I've finally fixed the problem in master branch and made the solution super flexible. I've added :match
to allow for granular setting of matching behaviour when highlighting current breadcrumb. Hope you like it!
If i am on the root_path, the crumb does not gets the styles.
A solution could be to check by controller and action instead of the url.
Example:
If i am on the
/publications
the crumb is highlighted. If im on/
instead, its not.