Problem with ShopifyAPI::Order.find method in model of app

479 views
Skip to first unread message

Bengmn

unread,
Aug 9, 2011, 3:18:19 AM8/9/11
to shopify-api
hey guys,

I've been working on my first Shopify app and have to say it's gone
mostly pretty smoothly for me. What I wanted to write an app for was
to allow my shop to export all of the orders for the day into a
specially formatted text file. What I've done is set up a rails app
using the shopify gem and the following tutorial:
http://wiki.shopify.com/Creating_an_app_and_deploying_it_to_Heroku.

At first I modified the Home controller to basically perform my
function entirely in the index command to get it working. Everything
seemed to be great so I decided it was time to refactor my action
script into something a little more rubyish and I set up a Reports
model and controller in order to better fragment my code. The problem
in my app occurs when I invoke the create method on a report object
from the Reports controller. The create method resides in the Report
class which is a model. The error I keep getting points me to the
following line:

app/models/report.rb:34:
@orders = ShopifyAPI::Order.find(:all, :params => { :created_at_min =>
"#{@date} 00:00", :created_at_max => "#{@date} 23:59", :order =>
"created_at DESC" })

The error I get is:

Started POST "/reports" for 127.0.0.1 at 2011-08-09 02:51:54 -0400
Processing by ReportsController#create as HTML
Parameters: {"utf8"=>"✓",
"authenticity_token"=>"fCQw3Pegyv069jO0tZ4eY5buslyAM/r8yrG7phyoJqI=",
"id"=>"20110804", "commit"=>"Create"}
Completed 500 Internal Server Error in 9ms

NoMethodError (undefined method `path' for nil:NilClass):
app/models/report.rb:34:in `create'
app/controllers/reports_controller.rb:9:in `create'

It seems like since I moved the call to the ShopifyAPI into my own
class I've prevented it from working properly. Not sure if leaving the
controller that was set-up by the tutorial app means I'm missing some
pieces or not but I figure you guys know exactly what sin I've
committed. Any help is appreciated. I also started a thread on S/O but
am not really getting the right help, there is more of my code posted
though: http://stackoverflow.com/q/6991675/541005

Thanks

Bengmn

unread,
Aug 9, 2011, 3:59:55 AM8/9/11
to shopify-api
So just as suspected I was missing code from my Report controller
which seems to have messed up the whole authentication scheme...

adding this code to my Reports controller resulted in everything
magically working:

around_filter :shopify_session, :except => 'welcome'

def welcome
current_host = "#{request.host}#{':' + request.port.to_s if
request.port != 80}"
@callback_url = "http://#{current_host}/login/finalize"
end


I assume in any controller I write this code will always need to be
present?

Thanks for the help.

Eugene Bolshakov

unread,
Aug 9, 2011, 6:57:11 AM8/9/11
to shopi...@googlegroups.com
Correct, you need the before filter. Check the source code of the shopify_app gem to find out what exactly it does (it's pretty simple): https://github.com/Shopify/shopify_app/blob/master/lib/shopify_app/login_protection.rb#L2

The "NoMethodError (undefined method `path' for nil:NilClass)" error appeared because ShopifyAPI::Base.site was not initialized.


Eugene Bolshakov

unread,
Aug 9, 2011, 6:59:19 AM8/9/11
to shopi...@googlegroups.com
Sorry, the around_filter, not before_filter.
Reply all
Reply to author
Forward
0 new messages