lassebunk / gretel Goto Github PK
View Code? Open in Web Editor NEWFlexible Ruby on Rails breadcrumbs plugin.
License: MIT License
Flexible Ruby on Rails breadcrumbs plugin.
License: MIT License
I think the url helper hack prevents the helpers from getting proper context information from the controller. Any ideas on how to solve this? Using thin with --prefix '/foo' lets you easily mount the app with a path prefix for testing.
Hi,
Thanks for the gem. I have been trying to use it with non restful routes and I cant seem to get it working. Mind having a look?
Config file:
crumb :root do
link "Home", root_path
end
crumb :products do
link "Products", products_path
parent :root
end
crumb :product_group do
link product_group.name, root_path # test
parent :products
end
I have these routes:
get "products" => "products#index", as: "products"
get "products/:group" => "products#group", as: "product_group"
get "products/:group/:family" => "products#family", as: "product_family"
get "products/:group/(:family)/:range" => "products#range", as: "product_range"
When I do the following in products/index.haml
, it works fine:
- breadcrumb :products
= breadcrumbs
Renders 'Home > Products'
However, when I try this in products/group.haml
, I get an error about :product
missing.
- breadcrumb @product_group
Breadcrumb :product not found.
I don't have a :product
resource, I have groups, families and ranges. Can't I create more or less custom breadcrumbs?
Hi, from heartcombo/devise#1678
I'll send you my test project
First, I'm quite new with both ruby and rails, so maybe I'm missing something obvious, but...
I'm using devise-2.0.4 with cancan-1.6.7.
When I'm requesting a new password to be sent by email, I got
NoMethodError (undefined method `_with_routes' for nil:NilClass):
actionpack (3.2.1) lib/action_dispatch/routing/routes_proxy.rb:14:in `url_options'
actionpack (3.2.1) lib/action_dispatch/routing/routes_proxy.rb:28:in `new_user_session_path'
actionpack (3.2.1) lib/action_dispatch/routing/routes_proxy.rb:32:in `method_missing'
devise (2.0.4) lib/devise/controllers/url_helpers.rb:50:in `new_session_path'
devise (2.0.4) app/controllers/devise/passwords_controller.rb:44:in `after_sending_reset_password_instructions_path_for'
...
I traced this error :
at url_helpers.rb:50
is sending a new_user_session_path
message to _devise_route_context
then url_options
is called but @scope is nil
As a workaround, in ApplicationController :
def new_session_path *args
case args[0]
when :user
new_user_session_path
else
raise "Unsupported scope: #{args[0]}"
end
end
thanks
[...]
in gretel/helper_methods.rb on lines 3 to 5:
include ActionView::Helpers::UrlHelper
def controller # hack because ActionView::Helpers::UrlHelper needs a controller method
end
when commented out, that's working
Hi there :)
I was just wondering how you'd recommend one test the breadcrumbs? I'm thinking some kind of helper spec? Any ideas would be greatly appreciated.
First off, let me say thank you for your nice little gem.
But I noticed a problem in 2.0.0beta1.
These two lines behave quite differently in a view :
<% breadcrumb :brands %>
<%= breadcrumb :brands %>
The first outputs
Home > brands
The second outputs
Home > brands
[]
This forces me to use option 1, but it kinda goes against the rails3 convention that view helper must have an equal sign when they output something.
Thoughts?
My crumb file is pretty simple :
Gretel::Crumbs.layout do
crumb :root do
link "Home", root_path
end
crumb :brands do
link "brands", brands_path
end
end
I'm getting /Users/lassebunk/dev/tmp/ogtest/config/initializers/breadcrumbs.rb:1: uninitialized constant Gretel (NameError)
Could anyone help figure this out?
Thanks in advance,
/Lasse
I am using this gem for my app.i wanted to know
ideatrdae-dev.herokuapp.com/startups?startup=All
First, thank you for the great gem. Gretel is the only easy way to do breadcrumbs on a rails app.
Is it possible to generate breadcrumbs that follow the actual path you took to get to a url?
My problem is, I have a request
view that you can get to from 2 other views. There are also subsequent views you can go to after request
.
Basically, there are many paths I could take to get to one view.
In the documentation, there is a parent_breadcrumb
helper, but I don't understand how to use that, or if it would be helpful.
Thanks,
Andrew
Hi there, I've got a method name conflict with the twitter-bootstrap-rails gem: render_breadcrumbs
.
Looks like that gem uses that method to render bootstrap compatible breadcrumbs.
Not sure what the solution is but I thought I'd raise it for discussion. Perhaps namespacing?
How would I set the outside class that the breadcrumbs should be inside of?
I've included the gem in my Gemfile. I've bundled. I used the generator to create the config file, which currently looks like:
crumb :root do
link "Account Overview", dashboard_root_path
end
I've added the breadcrumbs to the layout.
<%= breadcrumbs style: :bootstrap, display_single_fragment: true %>
But now, all I see is:
undefined method `breadcrumbs' for #<#<Class:0x007f82bbd1bfb0>:0x007f82c33eeb10>
Any thoughts?
It works
breadcrumbs(display_single_fragment: true) do |links|
react_component(BREADCRUMBS_COMPONENT, props: { links: links.to_a })
end
But show this message:
[Gretel] Calling `breadcrumbs` with a block has been deprecated and will be removed in Gretel version 4.0. Please use `tap` instead. Example:
breadcrumbs(autoroot: false).tap do |links|
if links.any?
# process links here
end
end
When i change to tap... not works
breadcrumbs(autoroot: false, display_single_fragment: true).tap do |links|
react_component(BREADCRUMBS_COMPONENT, props: { links: links.to_a })
end
In Rails 4.1.0.beta1 method engines
is removed from Rails::Engine::Railties
. I created fix for that without breaking backward compatibility.
But this fix adds ::Rails::Railtie.subclasses.map(&:instance)
to engines list.
I have multiple development environments, and Gretel only reloads the configuration files for the "development" environment. And as far as I can tell, this call is hard-coded in the gem. Or is there a way of changing this with a configuration value?
I like to have my crumbs look like this:
Home > Category > Subcategory >
Or such. I like that last greater-than sign at the end.
I can't just put this in application.html.erb because if there are no crumbs on a particular page, the ">" is there by itself (I don't show root breadcrumb).
Anyway, I overrode the breadcrumbs method to allow for a 'posttext' option. Sorry, I'd submit this in a git way, but I'm still a git newbie.
module Gretel
module HelperMethods
def breadcrumb(*args)
options = args.extract_options!
name, object = args[0], args[1]
if name
@_breadcrumb_name = name
@_breadcrumb_object = object
else
if @_breadcrumb_name
crumb = breadcrumb_for(@_breadcrumb_name, @_breadcrumb_object, options)
elsif options[:show_root_alone]
crumb = breadcrumb_for(:root, options)
end
end
if crumb && options[:pretext]
crumb = options[:pretext].html_safe + " " + crumb
end
if crumb && options[:posttext]
crumb = crumb + " " + options[:posttext].html_safe
end
crumb
end
end
end
Hey guys. I'm having issues while trying to render Gretel breadcrumbs, I started a thread on stackoverflow about it. Can you help me figure out what could be the reason?
http://stackoverflow.com/questions/21946362/rails-gretel-not-rendering
Currently, the dummy rails application is used only for unit tests.
It would be valuable to add some examples there for manual testing and to serve as a demonstration of various features.
Hey guys,
According to Gretel's documentation:
When configuring breadcrumbs inside a
crumb :xx do ... end
block, you have access to all methods that are normally accessible in the view where the breadcrumbs are inserted. This includes your view helpers, params, request, etc.
Does this mean that instance variables are explicitly excluded?
For example, my ApplicationController
sets a @current_website
instance variable which should then be available widely.
However:
crumb :root do
link @current_website.name, root_path
end
throws undefined method
name' for nil:NilClass`
What do I miss?
Hi Lasse,
Just wondering if you'd consider looping over all the registered engine config paths when looking for breadcrumbs files? I've had a quick search to see how this is done but haven't been able to find anything (though surely it's possible and is probably how route files are loaded out of engines too) :)
Using Gretel (3.0.5) and Rails (3.2.16) and put breadcrumbs.rb in config/
crumb :root do
link "Home", root_path
end
And put in my application.html.haml this:
- breadcrumbs pretext: "You are here: ", separator: " ›"
But don't render nothing, just empty, what make?
Hi Lasse :)
I'm having trouble with this code:
https://github.com/lassebunk/gretel/blob/master/lib/gretel/link_renderer.rb#L80
where it sets the link of the last crumb to be that of the current url. Is there a way to turn this off? I don't display a crumb for the current page so this overwrites what I intend to be the link for the parent crumb.
I'm playing with gretel on Windows with Sublime Text 3. My problem is very specific: I can't save the file while the server is running.
This is what happens:
If I CTRL+C my server, I can save normally. I know it works and I can go with this "issue", but it's very annoying have to restart the server every time gretel is changed.
Does gretel support internationalization with I18n? If so this a small example could be added to the README.
I found some unreleased feature in master. (diff: v3.0.8...025419b )
I can use it via bundler.
However It is useful for us if we can just install via gem install
.
Hello,
I'm having an issue where the breadcrumbs will not render for the root path the first time a user visits my app until that user visits a nested route. Once the user visits a nested route, the crumbs will load on the root path. I have display_single_fragment: true
in my layout file. The issue can't be replicated by clearing the cache. It can only be replicated by restarting the server or visiting the app from a different machine. It appears to happen regardless of which browser I use.
Thanks!
is there a solution go get gretel work with scoped routes?
my route file looks like:
scope "/:locale" do
resources :books
end
my Gretel file:
crumb :root do
link "Home", root_path
end
crumb :books do
link "Books", books_path
end
it does not work ...
thx, sorry for bad english
Hello,
The main method used in the layouts as per exemple:
<%= breadcrumbs pretext: "You're here: " %>
isn't accepting any arguments and gives the error:
wrong number of arguments (given 1, expected 0)
If you don't pass any argument the return is empty:
[]
Regards,
Sergio Maziano
Hello again!
Recently I've written an article for Sitepoint about your gem http://www.sitepoint.com/breadcrumbs-rails-gretel/ so maybe you would like to put this link somewhere in the docs so that users have some kind of an example to follow.
Cheers!
In development everything is great, but in production it shows
<ol class="hbreadcrumb breadcrumb"><li><a href="/dashboard">Dashboard</a></li><li><a href="/dashboard/orders">Orders</a></li><li class="current">Order #2</li></ol>
It shows like a html code, not like links.
Hello,
I have a site with 2 distinct areas, (public and admin). Both areas can access the same model, for example Posts. So, I created 2 breadcrumb files, public.rb and admin.rb. When rendering in the admin section, I only want the admin.rb breadcrumbs to be loaded.
Since both sections have a :new_post crumb, the pathing doesn't work as expected. Is this possible, or do I have to give namespaced names to each crumb, such as :new_admin_post?
This isn't an issue, I just wanted to say thanks for such a SANE gem. I've looked at other breadcrumb plugins and was surprised at how overly complicated they were. Yours is an absolutely perfect solution :)
When i have a crumb without a link but with a parent and link_current is set to true the link on the last element on breadcrumb is not the link of the parent.
view:
- breadcrumb :item, @item
= breadcrumbs link_current: true
breadcrumb.rb:
crumb :category do |category|
link category.name, category
parent :category, category.parent if category.parent
end
crumb :item do |item|
parent :category, item.category
end
Then the category has the link to the item and not the link to the category. I expected that the category link is rendered. Or am i wrong?
On the other side: when i don't set link_current (of set it to false) then the last category is not linked (but it should be linked)
Gretel specifies a dependency on rails
gem -
Line 20 in 8038a7c
rails
is just an "umbrella gem" that depends on all the components of Ruby on Rails framework - https://github.com/rails/rails/blob/86ca5b254109e64edeb6e142e656b8a8c247cac8/rails.gemspec - ActiveSupport, ActionPack, ActiveRecord, ...
I want to avoid installing actioncable
gem in my Rails application. When Gretel specifies rails
gem as a dependency then actioncable
becomes my transitive dependency automatically and there is no way to avoid installing it.
Depend only on these parts of Rails that Gretel actually uses, for example:
gem.add_dependency "railities", ">= 3.1.0"
gem.add_dependency "actionview", ">= 3.1.0"
I'm happy to make a PR if you accept the change.
When booting up my rails app either via rake test or rails server, I get 3 deprecation warnings as follows:
DEPRECATION WARNING: alias_method_chain is deprecated. Please, use Module#prepend instead. From module, you can access the original method using super. (called from <top (required)> at /Users/craig/Development/LW/mm2/config/application.rb:7)
The line failing is:
Bundler.require(*Rails.groups)
Upon debugging I found these warnings were issued during the loading of the gretel gem and on reviewing the code I found 3 places where alias_method_chain is called. I have created a pull request which seems to work in Ruby 1.9.3 through 2.2.3. I'll post the PR in a moment and would appreciate any feedback.
You may need to update the Building the breadcrumbs manually
example in your README.md
with this new .tap
functionality.
Thank you for this excellent gem.
I think i am running into an issue with the :link_current option though.
(on Rails 4.2.4 and Gretel version gretel-3.0.8)
while trying to provide a different link to the current tag like so:
crumb :employees do
link "Employees ", employees_path
end
crumb :employee do | employee |
link "#{employee.name} (#{employee.code})", "/go/here"
parent :employees
end
View:
/employees/edit.html.erb
<% breadcrumb :employee, @employee%>
the link here is rendered as /employees/[ID]/edit
/employees/show.html.erb
<% breadcrumb :employee, @employee %>
the link here is rendered as /employees/[ID]
it doesn't link to "/go/here" link that I provide.
Isn't this behavior incorrect?
Thanks.
Hi mate,
I have just installed gretel and when I am going to install the configuration after running bundle install, I get
"Could not find generator gretel:install"
I am on Rails 4
Thanks
Hi Lasse,
In trying to figure out the other issue, I've upgraded to the latest gretel and now find that if I don't have a :root
crumb, the crumbs fail to render at all. I use my own partial to render the breadcrumbs so breadcrumbs
in the view ends up being an empty array.
My app has many different roots so I prefer to not have a root defined and just imply the root by not calling a parent crumb. Is this still possible? My code to render my crumbs is as follows:
- breadcrumbs do |links|
- if links.any?
%ul.breadcrumb
- links.each do |link|
%li
= link_to link.text, link.url
%span.divider >
In my views, I'm calling breadcrumb
like so:
breadcrumb :categories
or sometimes
breadcrumb :category, @category
I also have a separate partial, where I render the breadcrumbs in a loop to be included in my layout.
Now, I want to cache the output of my this partial so it's not constantly hitting the DB when rendering the breadcrumbs. How to do that using fragment caching?
I'm new to caching in Rails, but my understanding is that I should get whatever it was I had passed to breadcrumb
and create a cache_key
based off that.
It would be nice if I could call breadcrumb
without any arguments, to get whatever was previously set as the current breadcrumb.
So then I could do something like this in my breadcrumb partial:
<% cache(breadcrumb) do %>
<% breadcrumbs.tap do |links| %>
<% if links.any? %>
<div class="breadcrumbs breadcrumbs-fixed" id="layout-breadcrumbs">
<div class="container">
<ul class="breadcrumb">
<% links.each do |link| %>
<li<%= ' class="current"' if link.current? %>>
<% if link.icon.present? %>
<i class="ace-icon<%= " #{link.icon}" %>"></i>
<% end %>
<% if link.current? %>
<%= link.text %>
<% else %>
<%= link_to link.text, link.url %>
<% end %>
</li>
<% end %>
</ul>
</div>
</div>
<% end %>
<% end %>
<% end %>
Reading the doco though, it doesn't look like that is possible.
Is there any easy way to get the current breadcrumb (or really whatever object/symbol passed to breadcrumb
), without looping through the actual breadcrumbs (and triggering a DB lookup)?
It seems there is an issue using slim (my case) or haml (please see the following links below) to display the breadcrumbs rendered.
http://stackoverflow.com/questions/21946362/rails-gretel-not-rendering
http://stackoverflow.com/questions/18003344/make-breadcrumb-with-gretel-in-rails
Not sure it is effectively related to these template engines but didn't find how to debug it.
Firstly, thanks for the great gem :)
Is it possible to add no class to the container element, and no id?
<%= breadcrumbs style: :ul,
autoroot: false,
link_current: true,
class: false,
id: false,
semantic: true %>
At the moment that generates "false" as the name and id. If I use class: ""
It naturally returns an empty class attribute in the html, which isn't ideal.
Thanks again and all the best,
Luke
Hi,
When using this gem with Foundation 6
and style: :foundation5
, "pretext" does not wrap <span>
with a <li>
tag.
All other links are, which make the display broken.
I'm trying to have breadcrumbs for my admin area (but not my regular site). As such I don't want it to go to root_path.
When I do this however, none of them show up:
crumb :admin do
link 'Dashboard', admin_path
end
crumb :admin_posts do
link 'Posts', admin_posts_path
end
crumb :admin_post do |post|
link post.title.present? ? post.title : 'New Post'
parent :admin_posts
end
If I change :admin
to :root
, then :posts
and :post
shows up but not :root
(my admin dashboard).
How would I go about doing this?
Can I set a default style for breadcrumbs somehow in config/breadcrumbs.rb
or do I have to manually set it every time? I couldn't find a way in the README or the code.
Hello!
First of all, thank you for this great gem, really nice and easy to use.
I have one question though. In my breadcrumbs.rb
I have:
crumb :root do
link 'Home', root_path
end
In my layout I have:
<%= breadcrumbs separator: " › " %>
In my view for the main page I have
<% breadcrumb :root %>
What I expect to see is something like this:
<div class="breadcrumbs">
<span class="current">Home</span>
</div>
However nothing shows up on the main page. Breadcrumbs on other pages are displayed without any problems. Is there any way to achieve this or am I doing something wrong?
Hello, and thanks for a great plugin. I have 2 questions/suggestions:
When running rails 4.2.6 and gretel 3.0.8 on jRuby 9.1.0.0 it yields the following error:
uninitialized constant error Rails::Application::Railties not found
when the view helper <%= breadcrumbs style: :bootstrap %> is called.
Replacing https://github.com/lassebunk/gretel/blob/master/lib/gretel.rb#L19 with the following code resolves the issue:
engines = Rails::Engine::Railties.respond_to?(:engines) ? Rails::Engine::Railties.engines : Rails::Engine.subclasses.map(&:instance)
I've been trying to move from v1 of gretel to v3, and I'm running into a problem. We use the title
attribute on our links to give additional context to the breadcrumb text. In v1, we do something like:
link crumb_text, search_url(:q => query, :loc => geo), :title => search_title(:q => query, :loc => geo)
So, for example, hovering over "Seattle" in a breadcrumb like:
Home > Rated Lawyers > Business > Seattle
will show the tooltip "Seattle Business Lawyers".
This title text is based on the same parameters as the crumb text and the search url, so it was useful to have them all in the same place. The workaround of manually generating the breadcrumbs won't help, because there's no way to pass the context the title text needs through either the text
or the url
parameters of link
.
Before I work on a pull request to add this functionality back, I was wondering if there's a better way of doing this through Gretel as it currently exists? And would you accept that pull request, or was this removed for a specific reason?
<%= breadcrumbs %>
is generating
"<div class="breadcrumbs"></div>"
instead
<div class="breadcrumbs"></div>
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.