module Crummy::ControllerMethods::ClassMethods
Public Instance Methods
add_crumb(name, *args) { |instance| ... }
click to toggle source
Add a crumb to the crumbs array.
add_crumb("Home", "/") add_crumb(lambda { |instance| instance.business_name }, "/") add_crumb("Business") { |instance| instance.business_path }
Works like a before_filter so :only
and except
both work.
# File lib/crummy/action_controller.rb, line 11 def add_crumb(name, *args) options = args.extract_options! url = args.first raise ArgumentError, "Need more arguments" unless name or options[:record] or block_given? raise ArgumentError, "Cannot pass url and use block" if url && block_given? before_filter(options) do |instance| url = yield instance if block_given? url = instance.send url if url.is_a? Symbol if url.present? if url.kind_of? Array url.map! do |name| name.is_a?(Symbol) ? instance.instance_variable_get("@#{name}") : name end end if not url.kind_of? String url = instance.send :url_for, url end end # Get the return value of the name if its a proc. name = name.call(instance) if name.is_a?(Proc) _record = instance.instance_variable_get("@#{name}") unless name.kind_of?(String) if _record and _record.respond_to? :to_param instance.add_crumb(_record.to_s, url || instance.url_for(_record), options) else instance.add_crumb(name, url, options) end # FIXME: url = instance.url_for(name) if name.respond_to?("to_param") && url.nil? # FIXME: Add ||= for the name, url above end end
clear_crumbs()
click to toggle source
# File lib/crummy/action_controller.rb, line 46 def clear_crumbs before_filter do |instance| instance.clear_crumbs end end