Git Product home page Git Product logo

Comments (2)

weedySeaDragon avatar weedySeaDragon commented on June 17, 2024

I've solved this by using an abstract parent class controller that sets the parent link. The controller for the page is a subclass of that abstract parent class controller. The abstract parent controller sets the parent breadcrumb using before_action: { add_crumbs :section_parent_path, t('breadcrumbs.parent_section_crumb') } and then the child controller sets its own crumb : before_action: { add_crumbs :this_page_path, t('breadcrumbs.this_page_crumb') }
The before_action in the abstract parent class controller is called first, so that breadcrumb is added before the child controller ("this page").

Your example could be set up like this:

class AboutUsSectionController < ApplicationController
     before_action: { add_crumbs :about_path, t('breadcrumbs.about_us) }
    ...
  end

class LeadershipPagesController < AboutUsSectionController 
   before_action: { add_crumbs :about_leadership_path, t('breadcrumbs.leadership) }
  ...
end

Then the result would be:
Home / About Us / Leadership

(assuming, of course, those are the entries in your I18n .yml file)

Just one way to do it. (Perhaps concerns would also work.) I have other reasons to also have a parent controller class, so was a reasonable approach for me.

from breadcrumbs_on_rails.

rhnorment avatar rhnorment commented on June 17, 2024

Nice!. Thank you.

from breadcrumbs_on_rails.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.