From 1b98fee56e8a070c836a66aa05237a6d000fb970 Mon Sep 17 00:00:00 2001 From: Adrian Serafin Date: Mon, 16 Dec 2013 22:31:29 +0100 Subject: [PATCH] fix overwriting lambda with evaluated value --- lib/crummy/action_controller.rb | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/crummy/action_controller.rb b/lib/crummy/action_controller.rb index a720a21..aced77d 100644 --- a/lib/crummy/action_controller.rb +++ b/lib/crummy/action_controller.rb @@ -28,16 +28,20 @@ def add_crumb(name, *args) end end - # Get the return value of the name if its a proc. - name = name.call(instance) if name.is_a?(Proc) + if name.is_a?(Proc) + instance.add_crumb(name.call(instance), url, options) + return + end - _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) + unless name.kind_of?(String) + _record = instance.instance_variable_get("@#{name}") + if _record and _record.respond_to? :to_param + instance.add_crumb(_record.to_s, url || instance.url_for(_record), options) + return + end end - + + instance.add_crumb(name, url, options) # FIXME: url = instance.url_for(name) if name.respond_to?("to_param") && url.nil? # FIXME: Add ||= for the name, url above end