I am building a spree shop into an exiting Rails application, and I need to access link_to_cart
from outside of the Spree engine.
link_to_cart
can be found here: spree/core/app/helpers/spree/base_helper.rb
Since I have modified the styling in link_to_cart
, I also created:
#helpers/spree/base_helper_decorator.rb
module Spree
module BaseHelper
def link_to_cart(text = nil)
text = text ? h(text) : Spree.t('cart')
css_class = nil
if simple_current_order.nil? or simple_current_order.item_count.zero?
text = "#{text}: (#{Spree.t('empty')})"
css_class = 'empty'
else
text = "<i class='fa fa-shopping-cart'></i> #{text}: (#{simple_current_order.item_count}) <span class='amount'>#{simple_current_order.display_total.to_html}</span>".html_safe
css_class = 'full'
end
link_to text.html_safe, spree.cart_path, :class => "cart-info #{css_class} btn btn-small btn-success pull-right", style: "margin-left:10px;"
end
end
end
I have tried doing stuff like Spree::BaseHelper.link_to_cart outside of the engine, but I keep getting undefined local variable or method 'link_to_cart'
I found this on a different StackOverflow question, and it seems promising, but I'm not sure how to modify it for my needs:
module MyEngine
class Engine < Rails::Engine
initializer 'my_engine.action_controller' do |app|
ActiveSupport.on_load :action_controller do
helper MyEngine::ImportantHelper
end
end
end
end