Git Product home page Git Product logo

breadcrumbs_on_rails's Introduction

Breadcrumbs On Rails

BreadcrumbsOnRails is a simple Ruby on Rails plugin for creating and managing a breadcrumb navigation for a Rails project. It provides helpers for creating navigation elements with a flexible interface.

Build Status Tidelift dependencies

Links

Requirements

  • Ruby >= 2.4
  • Rails >= 5

For older versions use a previous release.

Installation

Add this line to your application's Gemfile:

gem "breadcrumbs_on_rails"

And then execute bundle to install the dependencies:

bundle

Use Bundler and the :git option if you want to grab the latest version from the Git repository.

Usage

Creating a breadcrumb navigation menu in your Rails app using BreadcrumbsOnRails is really straightforward.

In your controller, call add_breadcrumb to push a new element on the breadcrumb stack. add_breadcrumb requires two arguments: the name of the breadcrumb and the target path.

class MyController

  add_breadcrumb "home", :root_path
  add_breadcrumb "my", :my_path

  def index
    # ...

    add_breadcrumb "index", index_path
  end

end

See the section "Breadcrumb Element" for more details about name and target class types.

The third, optional argument is a Hash of options to customize the breadcrumb link.

class MyController
  def index
    add_breadcrumb "index", index_path, title: "Back to the Index"
  end
end

In your view, you can render the breadcrumb menu with the render_breadcrumbs helper.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  <title>untitled</title>
</head>

<body>
  <%= render_breadcrumbs %>
</body>
</html>

render_breadcrumbs understands a limited set of options. For example, you can pass change the default separator with the :separator option.

<body>
  <%= render_breadcrumbs :separator => ' / ' %>
</body>

Current possible options are:

  • :separator
  • :tag

To use with Bootstrap you might use the following:

<body>
  <ol class="breadcrumb">
    <%= render_breadcrumbs :tag => :li, :separator => "" %>
  </ol>
</body>

More complex customizations require a custom Builder.

HTML Escaping

The text of the breadcrumb is html-escaped by default unless it is a SafeBuffer, to prevent XSS attacks.

class MyController
  add_breadcrumb "This is the <b>Main</b> page".html_safe

  def profile
    add_breadcrumb "#{@user_name} Profile", users_profile
  end
end

In this case, if @user_name is <script>, it will output:

This is the <b>Main</b> page > &lt;script&gt; Profile

Breadcrumb Element

A breadcrumbs menu is composed by a number of Element objects. Each object contains two attributes: the name of the breadcrumb and the target path.

When you call add_breadcrumb, the method automatically creates a new Element object for you and append it to the breadcrumbs stack. Element name and path can be one of the following Ruby types:

  • Symbol
  • Proc
  • String

Symbol

If the value is a Symbol, the library calls the corresponding method defined in the same context the and sets the Element attribute to the returned value.

class MyController
  
  # The Name is set to the value returned by
  # the :root_name method.
  add_breadcrumb :root_name, "/"
  
  protected
  
    def root_name
      "the name"
    end
  
end

Proc

If the value is a Proc, the library calls the proc passing the current view context as argument and sets the Element attribute to the returned value. This is useful if you want to postpone the execution to get access to some special methods/variables created in your controller action.

class MyController

  # The Name is set to the value returned by
  # the :root_name method.
  add_breadcrumb Proc.new { |c| c.my_helper_method },
                 "/"

end

String

If the value is a String, the library sets the Element attribute to the string value.

class MyController

  # The Name is set to the value returned by
  # the :root_name method.
  add_breadcrumb "homepage", "/"

end

Restricting breadcrumb scope

The add_breadcrumb method understands all options you are used to pass to a Rails controller filter. In fact, behind the scenes this method uses a before_filter to store the tab in the @breadcrumbs variable.

Taking advantage of Rails filter options, you can restrict a tab to a selected group of actions in the same controller.

class PostsController < ApplicationController
  add_breadcrumb "admin", :admin_path
  add_breadcrumb "posts", :posts_path, only: [:index, :show]
end

class ApplicationController < ActionController::Base
  add_breadcrumb "admin", :admin_path, if: :admin_controller?
  
  def admin_controller?
    self.class.name =~ /^Admin(::|Controller)/
  end
end

Internationalization and Localization

BreadcrumbsOnRails is compatible with the standard Rails internationalization framework.

For example, if you want to localize your menu, define a new breadcrumbs node in your .yml file with all the keys for your elements.

# config/locales/en.yml
en:
  breadcrumbs:
    homepage: Homepage
    first: First
    second: Second
    third: Third

# config/locales/it.yml
it:
  breadcrumbs:
    homepage: Homepage
    first: Primo
    second: Secondo
    third: Terzo

In your controller, use the I18n.t method.

class PostsController < ApplicationController
  add_breadcrumb I18n.t("breadcrumbs.first"),  :first_path
  add_breadcrumb I18n.t("breadcrumbs.second"), :second_path, only: [:second]
  add_breadcrumb I18n.t("breadcrumbs.third"),  :third_path,  only: [:third]
end

class ApplicationController < ActionController::Base
  add_breadcrumb I18n.t("breadcrumbs.homepage"), :root_path
end

Support

Library documentation is auto-generated from the README and the source code, and it's available at https://rubydoc.info/gems/breadcrumbs_on_rails.

Commercial support available as part of the Tidelift Subscription - Learn more

The maintainers of breadcrumbs_on_rails and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. Consider subscribing to Tidelift which provides Enterprise support for this project.

Credits

BreadcrumbsOnRails was created and is maintained by Simone Carletti. Many improvements and bugfixes were contributed by the open source community.

Security and Vulnerability Reporting

Full information and description of our security policy please visit SECURITY.md

Changelog

See the CHANGELOG.md file for details.

License

Copyright (c) 2009-2020 Simone Carletti. This is Free Software distributed under the MIT license.

breadcrumbs_on_rails's People

Contributors

commel avatar d-natoli avatar dnnx avatar halfling-rram avatar henrik avatar jcoyne avatar mattmsumner avatar mpartel avatar nickcampbell18 avatar ochko avatar olleolleolle avatar rdunlop avatar simi avatar weppos avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

breadcrumbs_on_rails's Issues

Somehow move #add_breadcrumb method from controller level

It is about the obvious (am i right?) need of not having controllers overwhelmed by #add_breadcrumb methods.

For now using your plugin requires inclusion one #add_breadcrumb method to each action of each controller.

One of the possibility I see here:

Fx if I add #add_breadcrumb into #show action of UsersController - I actualy dealing with "route user_path(@user)"-"view level" mapping - not controller's one. Right?

Why not to create somehow "routes - breadcrumbs" map in some non-controller place, base it on Rails routes recognization mechanism - and access it through controller&view helpers. Will be much more cleaner.

Does it makes sense? I know this proposal slightly attacks present design, but your plugin is almost there to be the best (fresh, working, configurable, ...) rails plugin completely providing breadcrumb functionality among all others I've been trying to find.

At least I'm wondering about possibility of having all breadcrumb declaration stuff collected in one place!

Thanks.

And thanks for the gem!

ActionView::Template::Error (can't convert Symbol into String)

Using unicorn and rails 3.2.13
in production have bug
ActionView::Template::Error (can't convert Symbol into String):
1: <div class="faixa2-interna"> 2: <div class="faixa2-interna-content"> 3: <%= render_breadcrumbs raw("&raquo;") %> 4: </div> 5: </div>
app/views/layouts/processo_seletivo/_barra_links.html.erb:3:in _app_views_layouts_processo_seletivo__barra_links_html_erb__2678631049141784605_67002920' app/views/layouts/processo_seletivo.html.erb:16:in_app_views_layouts_processo_seletivo_html_erb___1052092167412163333_65725860'

Debug details:
Exception TypeError' at /home/apps/sgo/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/core_ext/string/output_safety.rb:169 - can't convert Symbol into String ExceptionActionView::Template::Error' at /home/apps/sgo/shared/bundle/ruby/1.9.1/gems/actionpack-3.2.13/lib/action_view/template.rb:321 - can't convert Symbol into String
Exception `ActionView::Template::Error' at /home/apps/sgo/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/notifications/instrumenter.rb:23 - can't convert Symbol into String

Last element is link too!

Hello
After update to 2.2.0 I found that the last element in breadcrumbs chain (current page) is generated as link.
Maybe something wrong?

breadcrumb trail is reset across controller boundaries

I am trying out the gem.

Noticed that the trail seems to be within controller; that is, it resets when navigating to a new controller thus destroying the trail.

Using: breadcrumbs_on_rails (2.2.0) / rails 3.0.12 / ruby1.8.7-p358.

Would appreciate advice.

Regards

rails 5 ActionController:API

Hi,

when i tried to extend rails 5 new actioncontroller:api, i get breadcrumb error:

/usr/local/rvm/gems/ruby-2.2.2/gems/breadcrumbs_on_rails-2.3.1/lib/breadcrumbs_on_rails/action_controller.rb:16:in `block in <module:ActionController>': undefined method `helper' for ActionController::API:Class (NoMethodError)
    from /usr/local/rvm/gems/ruby-2.2.2/bundler/gems/rails-d3150c81061f/activesupport/lib/active_support/concern.rb:120:in `class_eval'
    from /usr/local/rvm/gems/ruby-2.2.2/bundler/gems/rails-d3150c81061f/activesupport/lib/active_support/concern.rb:120:in `append_features'
    from /usr/local/rvm/gems/ruby-2.2.2/gems/breadcrumbs_on_rails-2.3.1/lib/breadcrumbs_on_rails/railtie.rb:14:in `include'
    from /usr/local/rvm/gems/ruby-2.2.2/gems/breadcrumbs_on_rails-2.3.1/lib/breadcrumbs_on_rails/railtie.rb:14:in `block (2 levels) in <class:Railtie>'
    from /usr/local/rvm/gems/ruby-2.2.2/bundler/gems/rails-d3150c81061f/activesupport/lib/active_support/lazy_load_hooks.rb:38:in `instance_eval'
    from /usr/local/rvm/gems/ruby-2.2.2/bundler/gems/rails-d3150c81061f/activesupport/lib/active_support/lazy_load_hooks.rb:38:in `execute_hook'
    from /usr/local/rvm/gems/ruby-2.2.2/bundler/gems/rails-d3150c81061f/activesupport/lib/active_support/lazy_load_hooks.rb:45:in `block in run_load_hooks'
    from /usr/local/rvm/gems/ruby-2.2.2/bundler/gems/rails-d3150c81061f/activesupport/lib/active_support/lazy_load_hooks.rb:44:in `each'
    from /usr/local/rvm/gems/ruby-2.2.2/bundler/gems/rails-d3150c81061f/activesupport/lib/active_support/lazy_load_hooks.rb:44:in `run_load_hooks'
    from /usr/local/rvm/gems/ruby-2.2.2/bundler/gems/rails-d3150c81061f/actionpack/lib/action_controller/api.rb:144:in `<class:API>'
    from /usr/local/rvm/gems/ruby-2.2.2/bundler/gems/rails-d3150c81061f/actionpack/lib/action_controller/api.rb:87:in `<module:ActionController>'
    from /usr/local/rvm/gems/ruby-2.2.2/bundler/gems/rails-d3150c81061f/actionpack/lib/action_controller/api.rb:5:in `<top (required)>'
    from /var/www/project/app/controllers/mobile_application_controller.rb:1:in `<top (required)>'

Not rendering links in action create

Hey! ;]

I'm facing a problem with my action create. For example, when I need render action new for some info missing, the link for action create is the same for action index, then the breadcrumb with link to index is not rendering properly. Perhaps change the link_to_unless_current to create the path with controller and action instead the path resolve the problem.

It is possible?
Thanks!

wrong number of arguments (0 for 1) on %= render_breadcrumbs.

I just barely installed render_breadcrumbs on Rails 3.2.15 & Ruby 2.1.0 and I cant seem to get around this error.
In a view

<%= render_breadcrumbs %>

throws a "wrong number of arguments (0 for 1)", error. Googling it I have been unable to find anyone with the same problems. Is there something that I am doing wrong?

only and except options?

At the moment, I have to do this:

  before_filter :add_breadcrumbs, except: :index

  private

  def add_breadcrumbs
    add_breadcrumb SuccessCriterion.model_name.human(count: :other), :success_criteria_path
  end

It would be nicer to do this:

before_filter :add_breadcrumb, SuccessCriterion.model_name.human(count: :other), :success_criteria_path, except: :index

options hash works only inside action

I'm using version 2.1, with this code in the controller:

class MessagesController < ApplicationController

  add_breadcrumb "Dashboard", "/", :title => "Dashboard"

  def index
    add_breadcrumb "Dashboard", "/", :title => "Dashboard"
  end
end

the output is:

<a href="/">Dashboard</a>
»
<a title="Message" href="/">Message</a>

The options hash seems to work only inside the actions

Separator throwing an error

Bread crumbs are working fine with the following:
<%= render_breadcrumbs%>

But adding the separator throws an error
<%= render_breadcrumbs :separator => ' / ' %>

Error:
NoMethodError in Customers#index

Showing /Users/thurstonjm/.rvm/gems/ruby-1.9.3-p392/gems/twitter-bootstrap-rails-2.2.8/app/views/twitter-bootstrap/_breadcrumbs.html.erb where line #3 raised:

undefined method `html_safe' for {:separator=>"/"}:Hash
Extracted source (around line #3):

1: <% if @breadcrumbs.present? %>
2:


    3: <% separator = divider.html_safe %>
    4: <% @breadcrumbs[0..-2].each do |crumb| %>
    5:

  • 6: <%= link_to crumb[:name], crumb[:url], crumb[:options] %>

Problem with param :title

Repro:
Add followed line in 'application_controller.rb' file:

add_breadcrumb 'home', :root_path, title: "My best web application"

Run your rails app

What's bad:
"title" param doesn't appear in <a href"...">...</a> tag code.

It should be:
String "My best web application" should be included in title param:

<a href"..." title="My best web application">...</a>

How to fix it:

  1. Open "action_controller.rb" file of the "Breadcrumbs On Rails" plugin:
  2. Correct "before_filter" block into:
before_filter(filter_options) do |controller|
  controller.send(:add_breadcrumb, name, path, filter_options)
end

The whole code should be:

def add_breadcrumb(name, path = nil, filter_options = {})
  # This isn't really nice here
  if eval = Utils.convert_to_set_of_strings(filter_options.delete(:eval), %w(name path))
    name = Utils.instance_proc(name) if eval.include?("name")
    path = Utils.instance_proc(path) if eval.include?("path")
  end

  before_filter(filter_options) do |controller|
    controller.send(:add_breadcrumb, name, path, filter_options)
  end
end

It works for me.

Thank you I hope it's helpfull.

Btw. I prefer "Breadcrumbs On Rails" to "Crummy" because:
a) it checks every crumb if it is current_page. If not then it's not linked :-)
b) adding crumbs is much simplier:

add_crumber 'home', :root_path

vs

add_crumb( 'home') { |instance| instance.send :root_path }

Use custom Builder as default for an application?

Is there a way to make a custom Builder the default for an app? Not the default for the gem, but just on a specific application?

I'm using the BootstrapBreadcrumbsBuilder, which is a great option, but using the :builder option every time is a little cumbersome:

<%= render_breadcrumbs :builder => BootstrapBreadcrumbsBuilder %>

I thought I might be able to just rename my class to SimpleBuilder to overwrite the default, but that didn't work. Are there any other ways to allow me to just write render_breadcrumbs and have it use my Builder?

undefined method helper for ActionController::API:Class (NoMethodError)

I got this error when trying integrate breadcrumbs_on_rails with Rails 5:

/Users/hoanghoa/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/breadcrumbs_on_rails-2.3.1/lib/breadcrumbs_on_rails/action_controller.rb:16:in `block in <module:ActionController>': undefined method `helper' for ActionController::API:Class (NoMethodError)
from /Users/hoanghoa/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.beta1/lib/active_support/concern.rb:120:in `class_eval'
from /Users/hoanghoa/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.beta1/lib/active_support/concern.rb:120:in `append_features'
from /Users/hoanghoa/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/breadcrumbs_on_rails-2.3.1/lib/breadcrumbs_on_rails/railtie.rb:14:in `include'
from /Users/hoanghoa/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/breadcrumbs_on_rails-2.3.1/lib/breadcrumbs_on_rails/railtie.rb:14:in `block (2 levels) in <class:Railtie>'
from /Users/hoanghoa/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.beta1/lib/active_support/lazy_load_hooks.rb:38:in `instance_eval'
from /Users/hoanghoa/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.beta1/lib/active_support/lazy_load_hooks.rb:38:in `execute_hook'
from /Users/hoanghoa/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.beta1/lib/active_support/lazy_load_hooks.rb:45:in `block in run_load_hooks'
from /Users/hoanghoa/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.beta1/lib/active_support/lazy_load_hooks.rb:44:in `each'
from /Users/hoanghoa/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.beta1/lib/active_support/lazy_load_hooks.rb:44:in `run_load_hooks'
from /Users/hoanghoa/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-5.0.0.beta1/lib/action_controller/api.rb:144:in `<class:API>'
from /Users/hoanghoa/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-5.0.0.beta1/lib/action_controller/api.rb:87:in `<module:ActionController>'
from /Users/hoanghoa/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-5.0.0.beta1/lib/action_controller/api.rb:5:in `<top (required)>'
from /Users/hoanghoa/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.beta1/lib/active_support/dependencies.rb:302:in `require'
from /Users/hoanghoa/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.beta1/lib/active_support/dependencies.rb:302:in `block in require'
from /Users/hoanghoa/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.beta1/lib/active_support/dependencies.rb:266:in `block in load_dependency'
from /Users/hoanghoa/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.beta1/lib/active_support/dependencies.rb:682:in `new_constants_in'
from /Users/hoanghoa/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.beta1/lib/active_support/dependencies.rb:266:in `load_dependency'
from /Users/hoanghoa/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.beta1/lib/active_support/dependencies.rb:302:in `require'
from /Users/hoanghoa/projects/abc-ror/app/controllers/api/v1/application_controller.rb:1:in `<top (required)>'
from /Users/hoanghoa/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.beta1/lib/active_support/dependencies.rb:492:in `load'
from /Users/hoanghoa/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.beta1/lib/active_support/dependencies.rb:492:in `block in load_file'
from /Users/hoanghoa/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.beta1/lib/active_support/dependencies.rb:682:in `new_constants_in'
from /Users/hoanghoa/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.beta1/lib/active_support/dependencies.rb:491:in `load_file'
from /Users/hoanghoa/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.beta1/lib/active_support/dependencies.rb:388:in `block in require_or_load'
from /Users/hoanghoa/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.beta1/lib/active_support/dependencies.rb:37:in `block in load_interlock'
from /Users/hoanghoa/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.beta1/lib/active_support/dependencies/interlock.rb:12:in `block in loading'
from /Users/hoanghoa/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.beta1/lib/active_support/concurrency/share_lock.rb:115:in `exclusive'
from /Users/hoanghoa/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.beta1/lib/active_support/dependencies/interlock.rb:11:in `loading'
from /Users/hoanghoa/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.beta1/lib/active_support/dependencies.rb:37:in `load_interlock'
from /Users/hoanghoa/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.beta1/lib/active_support/dependencies.rb:369:in `require_or_load'
from /Users/hoanghoa/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.beta1/lib/active_support/dependencies.rb:345:in `depend_on'
from /Users/hoanghoa/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.beta1/lib/active_support/dependencies.rb:261:in `require_dependency'
from /Users/hoanghoa/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/railties-5.0.0.beta1/lib/rails/engine.rb:476:in `block (2 levels) in eager_load!'
from /Users/hoanghoa/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/railties-5.0.0.beta1/lib/rails/engine.rb:475:in `each'
from /Users/hoanghoa/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/railties-5.0.0.beta1/lib/rails/engine.rb:475:in `block in eager_load!'
from /Users/hoanghoa/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/railties-5.0.0.beta1/lib/rails/engine.rb:473:in `each'
from /Users/hoanghoa/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/railties-5.0.0.beta1/lib/rails/engine.rb:473:in `eager_load!'
from /Users/hoanghoa/projects/abc-ror/config.ru:6:in `block in <main>'
from /Users/hoanghoa/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rack-2.0.0.alpha/lib/rack/builder.rb:55:in `instance_eval'
from /Users/hoanghoa/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rack-2.0.0.alpha/lib/rack/builder.rb:55:in `initialize'
from /Users/hoanghoa/projects/abc-ror/config.ru:in `new'
from /Users/hoanghoa/projects/abc-ror/config.ru:in `<main>'
from /Users/hoanghoa/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rack-2.0.0.alpha/lib/rack/builder.rb:49:in `eval'
from /Users/hoanghoa/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rack-2.0.0.alpha/lib/rack/builder.rb:49:in `new_from_string'
from /Users/hoanghoa/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rack-2.0.0.alpha/lib/rack/builder.rb:40:in `parse_file'
from /Users/hoanghoa/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rack-2.0.0.alpha/lib/rack/server.rb:318:in `build_app_and_options_from_config'
from /Users/hoanghoa/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rack-2.0.0.alpha/lib/rack/server.rb:218:in `app'
from /Users/hoanghoa/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/railties-5.0.0.beta1/lib/rails/commands/server.rb:56:in `app'
from /Users/hoanghoa/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rack-2.0.0.alpha/lib/rack/server.rb:353:in `wrapped_app'
from /Users/hoanghoa/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/railties-5.0.0.beta1/lib/rails/commands/server.rb:134:in `log_to_stdout'
from /Users/hoanghoa/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/railties-5.0.0.beta1/lib/rails/commands/server.rb:74:in `start'
from /Users/hoanghoa/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/railties-5.0.0.beta1/lib/rails/commands/commands_tasks.rb:90:in `block in server'
from /Users/hoanghoa/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/railties-5.0.0.beta1/lib/rails/commands/commands_tasks.rb:85:in `tap'
from /Users/hoanghoa/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/railties-5.0.0.beta1/lib/rails/commands/commands_tasks.rb:85:in `server'
from /Users/hoanghoa/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/railties-5.0.0.beta1/lib/rails/commands/commands_tasks.rb:49:in `run_command!'
from /Users/hoanghoa/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/railties-5.0.0.beta1/lib/rails/command.rb:20:in `run'
from /Users/hoanghoa/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/railties-5.0.0.beta1/lib/rails/commands.rb:19:in `<top (required)>'
from /Users/hoanghoa/projects/abc-ror/bin/rails:9:in `require'
from /Users/hoanghoa/projects/abc-ror/bin/rails:9:in `<top (required)>'
from /Users/hoanghoa/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/spring-1.6.1/lib/spring/client/rails.rb:28:in `load'
from /Users/hoanghoa/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/spring-1.6.1/lib/spring/client/rails.rb:28:in `call'
from /Users/hoanghoa/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/spring-1.6.1/lib/spring/client/command.rb:7:in `call'
from /Users/hoanghoa/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/spring-1.6.1/lib/spring/client.rb:28:in `run'
from /Users/hoanghoa/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/spring-1.6.1/bin/spring:51:in `<top (required)>'
from /Users/hoanghoa/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/spring-1.6.1/lib/spring/binstub.rb:11:in `load'
from /Users/hoanghoa/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/spring-1.6.1/lib/spring/binstub.rb:11:in `<top (required)>'
from /Users/hoanghoa/.rbenv/versions/2.3.0/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/hoanghoa/.rbenv/versions/2.3.0/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/hoanghoa/projects/abc-ror/bin/spring:13:in `<top (required)>'
from bin/rails:3:in `load'
from bin/rails:3:in `<main>'

Polymorphic paths

Couldn't get this to work in controller...

add_breadcrumb @management.name, [:admin, @management]

It resolves the url to:

http://localhost:3000/admin/managements/1/[:admin,%20#<Management%20id:%201,%20name:%20"GLL",%20address_line_1:%20nil,%20address_line_2:%20nil,%20borough:%20nil,%20city:%20"London",%20postcode:%20nil,%20telephone_number:%20nil,%20email:%20nil,%20website:%20nil,%20tldc_id:%20nil,%20tldc_approved:%20true,%20created_at:%20"2011-10-25%2011:33:08",%20updated_at:%20"2011-10-25%2011:33:08">]

Custom Builder Example

Is there an example anywhere on how I can use a custom builder with this gem to customize the html that gets generated by render_breadcrumbs?

Compatibility with Friendly ID

I'm using this gem and Friendly ID in one of my projects.

def show
  @section = Section.friendly.find(params[:id])
  add_breadcrumb 'Introduction', section_path(@section)
end

This doesn't return an active link in the html, just plain text. Is there a workaround for this or am I just doing something wrong?

Rails 3.2 Deprecation warnings ActiveSupport::Concern

DEPRECATION WARNING: The InstanceMethods module inside ActiveSupport::Concern will be no longer included automatically. Please define instance methods directly in BreadcrumbsOnRails::ControllerMixin instead. (called from require at /Users/imac2011/.rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.1.3/lib/bundler/runtime.rb:68)

Separator displays options hash

Unsure what is causing this or if its a conflict with something else going on in my app.
However in development the options that are being passed to render_breadcrumbs are being displayed in the view. I have been unable to find anything on the web about this issue.

Development Env:

<%= render_breadcrumbs :separator => "&raquo;" %>

results in the following:
Screen Shot 2012-12-12 at 12 26 37 PM

Production (hosted on heroku) shows correctly:
Screen Shot 2012-12-12 at 12 32 51 PM

The second part to this is that you will notice from the screenshots that development renders the bootstrap styled breadcrumb without a specified builder however the production environment does not. A bootstrap builder must be specified for production but not development?

Make Second Argument on add_breadcrumb Optional

I was previously using the Crummy gem which is very similar to yours but yours seems much more reliable. The only problem that I have is that you can't do something like add_breadcrumb "Current Page" which in Crummy would just render text instead of a link to indicate that you're currently on that page. It would be a nice if you could include this in one of your future updates.

Keep up the good work!

Breadcrumbs don't show up when added using an after_filter

class ApplicationController < ActionController::Base
  before_filter :add_breadcrumbs # works
  after_filter :add_breadcrumbs # doesn't work

  private
  def add_breadcrumbs
    add_breadcrumb t("iq_breadcrumb.home"), root_path
    add_breadcrumb t("iq_breadcrumb.controller.#{params[:controller]}"), url_for(action: :index)
  end
end

Is this the expected behavior? It wold be nice to also be able to add breadcrumbs in an after filter wherein I could access instance variables that the action created.

Thank you.

breadcrumbs on RESTful resources

Suppose you have a scaffold on "photos" (e.g. http://guides.rubyonrails.org/routing.html). The "resources :photos" generates paths which are the same but the verb is different (for example GET /photos and POST /photos). I'm trying to achieve the following:

if I access the list of photos then render as breadcrumbs: Home (as link) > Photos
Then, when I go to create a new photo I want: Home (as link) > Photos (as link) > Create new photo

The problem I have is in the "new photo" form. If I don't provide a mandatory field, my model will complain (via a validation) and the form will be displayed again with the corresponding error. However, the submit button has invoked POST /photos which, as far as the breadcrumbs are concerned, it's the same as GET /photos. So I end up having: Home (as link) > Photos (as link) -> Create new photo (as link) which, of course, is wrong. The last item should not be displayed as a link.

Any ideas how to fix this?

Many thanks in advance.

Deprecation warnings in Rails 5.0.0.beta1

I'm migrating an app to Rails 5.0.0.beta1 and I'm getting lots of deprecation warnings of this type:

  DEPRECATION WARNING: before_filter is deprecated and will be removed in Rails 5.1. Use before_action instead.

As far as I can see, this warning is generated here

Set element by symbol not working

If i try to set an element by symbol i got an undefined method `root_name'. Setup is like in the documentation:

...
add_breadcrumb :root_name, "/"
protected
def root_name
"the name"
end

...

last leaf is a link

Hi
For some reason the last part (leaf) of my breadcrum is a link but it should be just text.
Any idea how to solve it ?

Release to Rubygems?

Any chance we could get a release to Rubygems? The last released version, 2.3.0, is from Dec 2012, nearly 2.5 years old…

I know it's more work, thanks in advance for considering it.

Problem with translation

I'm using three languages ​​in my application, when changing language sometimes he translates, sometimes not.

How to solve?

Since I am using:
   add_breadcrumb I18n.t ("activerecord.models.account"): accounts_path
   add_breadcrumb I18n.t (: listing): accounts_path,: only => [: index]
   add_breadcrumb I18n.t (: new): new_account_path,: only => [: new,: create]
   add_breadcrumb I18n.t (: editLbl): edit_account_path,: only => [: edit,: update]

Deprecation warning in Rails 3.2.beta

Hello!

stanislaw@localhost ~/_work_/apps/magicdraw $be rails c
DEPRECATION WARNING: The InstanceMethods module inside ActiveSupport::Concern will be no 
longer included automatically. Please define instance methods directly in 
ActionController::Base instead. (called from include at 
/home/stanislaw/.rvm/gems/ruby-1.9.2-head/gems/breadcrumbs_on_rails-2.1.0/lib/breadcrumbs_on_rails/railtie.rb:19)
Loading development environment (Rails 3.2.0.beta)
ruby-1.9.2-head :001 > 

Thanks ;)

Adding a parent crumb?

Thanks for the great work!

If I have Pages controller for static web pages which have a navigation hierarchy, can I force the parent link to exist somehow?

pages_controller

def about
   add_breadcrumb  'About us', :about_path
end

def leadership
   add_breadcrumb  'Leadership', :about_leadership_path
end

The routing works fine, but the breadcrumbs do not render according to the routes. Could I do something like this?

pages_controller

def about
   add_breadcrumb  'About us', :about_path
end

def leadership
   add_breadcrumb  'Leadership', :about_leadership_path, options: { parent_path: :about_path }
end

Thanks in advance.

Non-Rails support

I used this plugin with Rails before and it was great. I now want to use it with Padrino, but there is a Rails dependency in the Gemspec

Add remote posibility

It could be useful to add the posibility to call the link generated into a breadcrumb with a data-remote="true" option. I'm facing this need right now and I think it could be easy to implement.

thanks and sorry for my bad english.

Appending <li> elements to each link

I tried passing a block to render_breadcrumbs, but maybe I am not doing it correctly.

This is the structure:

%ul.breadcrumb.breadcrumb-main
  %li
    %a{:href => "#"} Main page
    %span.divider
      %i.icon-caret-right
  %li
    %a{:href => "#"} Test
    %span.divider
      %i.icon-caret-right
  %li.text-info Dashboard

For some reason last breadcrumb is still a link

It works on other pages, but for this page in particular I am leaving out the breadcrumb to it's parent page, and now it doesn't seem to convert the last breadcrumb (the current page you are on) to just text.

Namespace collision with twitter-bootstrap-rails gem

Your Gem is incompatible with twitter-bootstrap-rails. Just wanted to put it up as an issue, so other people know. Maybe you'd want to add it to the readme.

Error message if I attempting to use the two gems together, using your syntax for add_breadcrumb:

can't convert Symbol into String

I've put up an issue on twitter-bootstrap-rails as well.

Mistake in documentation

hello, there,

You might want to revise your documentation on the description on the "String" type that an Element object can be made of.

Here's an extract.
--------------- extract start --------------------------------------
String

If the value is a Proc, the library sets the Element attribute to the string value.

--------------- extract end --------------------------------------

Aside from that, I'm excited in playing with this little plugin you made :)

thanks

Doesn't work as advertised: path helpers don't work in controller class context.

For example:

class CampaignsController < AR::Base

add_breadcrumb 'Campaigns', campaigns_path

...

end

Gives me:

undefined local variable or method `campaigns_path' for CampaignsController:Class

Should change the example to something like:

add_breadcrumb 'Campaigns', :campaigns_path <-- so that execution is deferred until the filter runs.

render_breadcrumbs don't put anchor around the generated crumb

render_breadcrumbs don't put anchor around the generated crumb. Is there any way to put an anchor so that user would click over it and navigate to the desired location?
I've already added "name" and "path" to add_breadcrumb in my controller.

add_breadcrumb "Home", :root_path
.
The issues is, how can a crumb be made clickable because it is not clickable so far.

Rails 2.3.x compatibility broken

Since your gem requires "ActiveSupport::Concern" (module controller_mixin extends from that) that is present only from Rails 3.0...

How can I use your gem on Rails 2.3.x?

> ruby script/server 
=> Booting Mongrel
=> Rails 2.3.11 application starting on http://0.0.0.0:3000

.../ruby/1.8/gems/activesupport-2.3.11/lib/active_support/dependencies.rb:182:in `require': no such file to load -- active_support/concern (MissingSourceFile)
from .../ruby/1.8/gems/activesupport-2.3.11/lib/active_support/dependencies.rb:182:in `require'
from .../ruby/1.8/gems/activesupport-2.3.11/lib/active_support/dependencies.rb:547:in `new_constants_in'
from .../ruby/1.8/gems/activesupport-2.3.11/lib/active_support/dependencies.rb:182:in `require'
from .../ruby/1.8/gems/breadcrumbs_on_rails-2.0.0/lib/breadcrumbs_on_rails.rb:16
... *omissis*...

Cucumber tests not finding render_breadcrumbs

Hello,

I am using breadcrumbs_on_rails v1.0.1 in a Rails 2.3.10 app by including the gem in my Gemfile. In my development environment I see no problems at all - the views render as expected. In my cucumber tests though, I get the following:

 undefined local variable or method `render_breadcrumbs' for #<ActionView::Base:0x1034c46f0> (ActionView::TemplateError)

1: = render_breadcrumbs

I've tried to use

 config.gem "breadcrumbs_on_rails"

in my config/environment.rb instead of including the gem in my Gemfile. I've also tried explicitly including BreadcrumbsOnRails in my spec_helper.rb -- no luck

Confused as to why the render_breadcrumbs helper is found in the dev environment but not in test. Any help appreciated!

Thanks,
Navin

undefined method `add_breadcrumb' for ApplicationController:Class

Hi any help would be great...

I am a Rails 3 on windows devkit installed Pik to 192. Ran the gem install view below:
*** LOCAL GEMS ***

abstract (1.0.0)
actionmailer (3.0.1)
actionpack (3.0.1)
activemodel (3.0.1)
activerecord (3.0.1)
activeresource (3.0.1)
activesupport (3.0.1)
arel (1.0.1)
babosa (0.2.0)
bcrypt-ruby (2.1.2)
breadcrumbs_on_rails (1.0.1)
builder (2.1.2)
bundler (1.0.3)
cancan (1.4.1, 1.4.0)
crummy (1.0.0)
devise (1.1.3)
erubis (2.6.6)
friendly_id (3.1.7)
haml (3.0.23)
hpricot (0.8.3, 0.8.2)
i18n (0.4.2)
mail (2.2.9.1, 2.2.9)
mime-types (1.16)
minitest (1.6.0)
mysql2 (0.2.6 x86-mingw32)
nifty-generators (0.4.2)
orm_adapter (0.0.3)
polyglot (0.3.1)
rack (1.2.1)
rack-mount (0.6.13)
rack-test (0.5.6)
rails (3.0.1)
railties (3.0.1)
rake (0.8.7)
rdoc (2.5.8)
ruby_parser (2.0.5)
sexp_processor (3.0.5)
sqlite3-ruby (1.3.2 x86-mingw32)
thor (0.14.4, 0.14.3)
treetop (1.4.8)
tzinfo (0.3.23)
warden (1.0.2, 0.10.7)

What am I missing why is the helper undefined?

controller:
class ApplicationController < ActionController::Base
protect_from_forgery
add_breadcrumb "home", :root_path
end

error message
undefined method `add_breadcrumb' for ApplicationController:Class

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.