Breadcrumbs in Ruby on Rails

前端 未结 6 857
猫巷女王i
猫巷女王i 2021-02-01 07:02

I\'m slightly insecure about my breadcrumb solution. Names and links are defined in each controller action:

Home         


        
6条回答
  •  梦毁少年i
    2021-02-01 07:36

    Breadcrumbs menu are a recurrent pattern in most Rails applications. To solve this issue, I created and released a plugin called breadcrumbs_on_rails.

    You define your breadcrumbs in the controller

    class MyController
    
      add_breadcrumb "home", root_path
      add_breadcrumb "my", my_path
    
      def index
        # ...
    
        add_breadcrumb "index", index_path
      end
    
    end
    

    and you render them in your view.

    
    
    
      
      untitled
    
    
    
      <%= render_breadcrumbs %>
    
    
    

    Even if you don't want to use a plugin, I encourage you to give it a look. It's open source and you can grab some idea for your app.

提交回复
热议问题