La solution fournie par chirantan est géniale. Si vous avez besoin de breabcrumbs pour le contrôleur avec espace de noms et que vous avez besoin de changer le fil d'Ariane en fonction de l'espace de noms, essayez ceci. Ce n'est pas parfait mais refactoriser comme vous avez besoin. Cela fonctionne pour mon projet.
Définir une nouvelle aide: navigation_helper.rb
module NavigationHelper
def navigation_add(title, url, namespace)
if defined? @@namespace and [email protected]@namespace.nil? and @@namespace == namespace
@@navigation ||= []
else
@@navigation = []
end
@@navigation << {title: title, url: url} unless title == "Home"
new_nav = []
@@navigation.each do |hash|
new_nav.push hash
if hash[:title].to_s == title.to_s
break
end
end
@@navigation = new_nav
@@navigation.uniq!
@@namespace = namespace
end
def render_navigation
if (request.path_parameters[:controller].sub('/', '::_').camelize + 'Controller').classify.constantize.action_methods.to_a.include? 'index'
navigation_add controller_name.camelize.to_s, request.path_parameters.merge({action: 'index'}).except(:id), params[:controller].include?('/') ? params[:controller].split("/").first : nil
end
if defined? @@navigation
render partial: 'navigation/navigation', locals: { navs: @@navigation, namespace: @@namespace }
else
render text: ''
end
end
end
ensuite définir une vue pour cette aide _navigation.haml
- unless navs.blank?
%ol.breadcrumb
- navs.each_with_index do |nav, index|
- if index == 0
%li=link_to fa_icon('arrow-left', text: 'Go Back'), :back
- unless namespace.nil?
%li
%h4.inline= request.fullpath.split('/')[1].gsub('-', '_').camelize
= fa_icon('angle-double-right')
%li= link_to_unless (nav[:title] == controller_name.camelize and action_name == 'index'), fa_icon(nav[:title].downcase.singularize, text: nav[:title]), nav[:url]