Module: RailsBreadcrumbs::ControllerAdditions
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/rails_breadcrumbs/controller_additions.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #add_breadcrumb_with_parent(object, path, options = {}) ⇒ Object
- #add_breadcrumbs_by_path(names = {}, options = {}) ⇒ Object
- #add_breadcrumbs_with_action_by_path(names = {}, options = {}) ⇒ Object
Instance Method Details
#add_breadcrumb_with_parent(object, path, options = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/rails_breadcrumbs/controller_additions.rb', line 17 def (object, path, ={}) return unless object.present? = ::RailsBreadcrumbs..merge() if defined?(Ancestry) && Ancestry::InstanceMethods.instance_methods.include?(:path) object.path.each do |element| (element, path, ) end elsif object.parent.present? [object.parent, object].each do |element| (element, path, ) end else (object, path, ) end end |
#add_breadcrumbs_by_path(names = {}, options = {}) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/rails_breadcrumbs/controller_additions.rb', line 33 def (names = {}, = {}) = ::RailsBreadcrumbs..merge() path_parts = controller_path.split('/') path_parts.each do |segment| link_name = segment.sub('_', ' ').camelcase link_name = names[segment] if names.has_key?(segment) name = I18n.t [:locale_root] + segment, :default => link_name if segment != path_parts.last route = nil path_parts.each do |temp| route = (route.nil? ? temp: route +'_'+ temp) break if temp == segment end link = send(route + '_path') else link = request.path end (name, link) end end |
#add_breadcrumbs_with_action_by_path(names = {}, options = {}) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/rails_breadcrumbs/controller_additions.rb', line 54 def (names = {}, = {}) = ::RailsBreadcrumbs..merge() path_parts = controller_path.split('/') << action_name path_parts.each do |segment| link_name = segment.sub('_', ' ').camelcase link_name = names[segment] if names.has_key?(segment) name = I18n.t [:locale_root] + segment, :default => link_name if segment != path_parts.last route = nil path_parts.each do |temp| route = (route.nil? ? temp: route +'_'+ temp) break if temp == segment end link = send(route + '_path') else link = request.path end (name, link) end end |