How to access Spree's current_order method from main application?

810 views
Skip to first unread message

A L

unread,
Jun 21, 2012, 6:12:28 AM6/21/12
to Spree
I'm trying to use the current_order method defined in the Spree::Core
engine: https://github.com/spree/spree/blob/master/core/lib/spree/core/current_order.rb

In my view, I've tried

Spree::Core::CurrentOrder.current_order

Using just "current_order" in development works fine though, but not
in production.

So then I've tried to require it in my views file like this:

require 'spree/core/current_order'

I've also tried permutations of these other solutions:

http://stackoverflow.com/questions/11124447/how-to-incorporate-rails-engine-applicationcontroller-methods-in-a-main-app

http://stackoverflow.com/questions/7323327/a-way-to-add-before-filter-from-engine-to-application/

http://stackoverflow.com/questions/8797690/rails-3-1-better-way-to-expose-an-engines-helper-within-the-client-app

But I've lost track of what I actually did.

Can someone please point me in the right direction? Maybe I
implemented the solutions in the above links incorrectly?

This is the error I'm getting in production:

2012-06-21T09:59:08+00:00 app[web.1]: ActionView::Template::Error
(undefined method `current_order' for
Spree::Core::CurrentOrder:Module):

If I comment out the lines of code with current_order, everything
works in production.

I'm thinking it's the way things are loaded in production? But this is
the first time I'm trying to deploy so I don't quite understand the
differences between development and production.

Thanks in advance!

A L

unread,
Jun 22, 2012, 4:41:56 PM6/22/12
to spree...@googlegroups.com
So I ended up creating a helper class in my application that requires and extends the Spree::Core::CurrentOrder module (or mixin the Spree::Core::CurrentOrder module?  I'm not sure what's the right term for it).

And it seems to work, but I then get a session method or variable is undefined error.

Then I happened upon this post:
https://groups.google.com/forum/?fromgroups#!topic/spree-user/wwjT6-ramVA

So I threw DRY out the window and just made a custom method to check for an existence of an order.

If this is the totally wrong way of doing things, then please let me know.

Thanks again!

A L

unread,
Jan 24, 2013, 2:53:22 AM1/24/13
to spree...@googlegroups.com
Hi Bionuc,

Thank you for the excellent info. I really appreciate you sharing it.
Next time I come across something similar, this will definitely come
in handy.

Take care!
Reply all
Reply to author
Forward
0 new messages