user6525564 user6525564 - 3 months ago 10
Ruby Question

Connecting with Quickbooks: Oauth Troubles, GrantUrl Error using qbo_api

Possible duplicate of Ruby on Rails integration with Quickbooks not working

I realize that this is a purely coding related error. I am unable to get my rails app to connect to Quickbooks due to my limited understanding of rails framework right now. Using this gem https://github.com/minimul/qbo_api, I got the button on my web app. However I still get a Routing error with my granturl section of code.

the command ruby App.rb from my console works very well. But integrating the Sinatra code in my rails app leads to this error.

This is my HomeApp.rb in config/initializers

class HomeApp < Sinatra::Base
require "bundler/setup"
require 'sinatra'
require 'json'
require 'openssl'
require 'base64'
require 'omniauth'
require 'omniauth-quickbooks'
require 'dotenv'
require 'qbo_api'
Dotenv.load "#{__dir__}/../.env"


PORT = 3000
CONSUMER_KEY = 'blah blah'
CONSUMER_SECRET = 'blah blah'

set :port, PORT
use Rack::Session::Cookie, secret: '34233adasf'
use OmniAuth::Builder do
....
....

end


In my config.ru I have the following

require ::File.expand_path('../config/environment', __FILE__)
run Rails.application
Dynopoker.configure do |config|
config.address = 'http://wakemydyno.com'
require "HomeApp"


The control passes to my index.erb file successfully but the error is thrown at this point

<script>
intuit.ipp.anywhere.setup({
grantUrl: "http://localhost:<%= @port %>/auth/quickbooks",


I use rails 4 and ruby 2 and my error says

No route matches [GET] "/auth/quickbooks"

Answer

Good thing, I was allowed to stew in my own stupidity while realizing the answer to this solution.

So I changed my routes.rb as follows:

Rails.application.routes.draw do
get "/" => HomeApp, :anchor =>false
match '/auth/:provider/callback' => 'quickbooks#callback', via: [:get,:post]

Also I removed the

'require HomeApp' 

line from my config.rufile.

Basically I created a quickbooks controller and added the callback.html.erb file for a callback action inside the controller. instead of using the Sinatra app for the callback, my code uses this quickbooks route just for the callback. The rest of the code flows solely from the Sinatra code.

No clue if this is the right approach to using the gem. But since it works, I am sticking with it for now.

Comments