【发布时间】:2016-08-18 21:03:47
【问题描述】:
我按照这个博客的说明进行操作,知道它已经很老了。 http://minimul.com/integrating-rails-and-quickbooks-online-via-the-version-3-api-part-1.html
我在我的网络应用程序上成功获得了“连接到 Quickbooks”按钮,但在单击它时,我收到以下错误。
NoMethodError in VendorsController#authenticate
undefined method `get_request_token' for nil:NilClass
错误的来源似乎是我的供应商控制器身份验证操作中的这一行:
token = $qb_oauth_consumer.get_request_token(:oauth_callback => callback)
我在 intuit 论坛上找到了我应该选中 Quickbooks 前面的框并在我的应用设置中取消选中付款的答案。我也做过。这也不会将我带到授权页面!
/app/contollers/vendors.rb
class VendorsController < ApplicationController
before_action :set_vendor, only: [:show, :edit, :update, :destroy]
# GET /vendors
# GET /vendors.json
def index
@vendors = Vendor.all
end
# GET /vendors/1
# GET /vendors/1.json
def show
end
# GET /vendors/new
def new
@vendor = Vendor.new
end
# GET /vendors/1/edit
def edit
end
# POST /vendors
# POST /vendors.json
def create
@vendor = Vendor.new(vendor_params)
respond_to do |format|
if @vendor.save
format.html { redirect_to @vendor, notice: 'Vendor was successfully created.' }
format.json { render action: 'show', status: :created, location: @vendor }
else
format.html { render action: 'new' }
format.json { render json: @vendor.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /vendors/1
# PATCH/PUT /vendors/1.json
def update
respond_to do |format|
if @vendor.update(vendor_params)
format.html { redirect_to @vendor, notice: 'Vendor was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: 'edit' }
format.json { render json: @vendor.errors, status: :unprocessable_entity }
end
end
end
# DELETE /vendors/1
# DELETE /vendors/1.json
def destroy
@vendor.destroy
respond_to do |format|
format.html { redirect_to vendors_url }
format.json { head :no_content }
end
end
def authenticate
callback = oauth_callback_vendors_url
*token = $qb_oauth_consumer.get_request_token(:oauth_callback => callback)*
session[:qb_request_token] = Marshal.dump(token)
redirect_to("https://appcenter.intuit.com/Connect/Begin?oauth_token=#{token.token}") and return
end
def oauth_callback
at = Marshal.load(session[:qb_request_token]).get_access_token(:oauth_verifier => params[:oauth_verifier])
session[:token] = at.token
session[:secret] = at.secret
session[:realm_id] = params['realmId']
redirect_to root_url, notice: "Your QuickBooks account has been successfully linked."
end
private
# Use callbacks to share common setup or constraints between actions.
def set_vendor
@vendor = Vendor.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def vendor_params
params.require(:vendor).permit(:name)
end
end
视图文件如下:
<!--Quickbooks stuff-->
<!-- this will display a button that the user clicks to start the flow -->
<% unless session[:token] %>
<ipp:connectToIntuit></ipp:connectToIntuit>
<% end %>`
<script type="text/javascript" src="https://appcenter.intuit.com/Content/IA/intuit.ipp.anywhere.js"></script>
<!-- configure the Intuit object: 'grantUrl' is a URL in your application which kicks off the flow, see below -->
<script>
intuit.ipp.anywhere.setup({menuProxy: '/path/to/blue-dot', grantUrl: '<%= authenticate_vendors_url %>'});
</script>
</body>
config/initializer/quickbooks.rb 文件
#Trying with custom code from "https://github.com/ruckus/quickbooks-ruby"
OAUTH_CONSUMER_KEY = "my app key"
OAUTH_CONSUMER_SECRET = "My APP Secret"
::QB_OAUTH_CONSUMER = OAuth::Consumer.new(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, {
:site => "https://oauth.intuit.com",
:request_token_path => "/oauth/v1/get_request_token",
:authorize_url => "https://appcenter.intuit.com/Connect/Begin",
:access_token_path => "/oauth/v1/get_access_token"
})
以下是我的 gemfile。
source 'https://rubygems.org'
gem 'nokogiri'
gem 'rack'
gem 'rails', '4.2.6'
#Action caching for Action Pack (removed from core in Rails 4.0).
gem 'actionpack-action_caching'
gem 'bootstrap-sass'
gem 'autoprefixer-rails'
gem 'bundler', '~>1.12.5'
# Use SCSS for stylesheets
gem 'sass-rails'
#charting rails
gem 'highcharts-rails'
gem 'quickbooks-ruby'
gem 'oauth-plugin'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
gem 'heroku'
#Passwordless Authentication
gem 'omniauth', '~> 1.3.1'
gem 'omniauth-auth0', '~> 1.4.1'
#DynoPoker to ping dyno every 30 mins so that loading time is not slow....hopefully!
gem 'dynopoker'
gem 'stripe'
group :development do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
#gem 'byebug'
# Use sqlite3 as the database for Active Record
gem 'pg'
end
group :production do
gem 'rails_12factor'
gem 'therubyracer'
end
group :test do
gem 'rspec'
end
我使用 ruby 2.3.0
任何想法我做错了什么?
【问题讨论】:
-
对于初学者,请发布一些代码,以便我们可以实际看到您在做什么。在您使用时也发布您的配置。
-
你可能听说过很多......所以我是 ROR 的新手
-
嗨@neutralCreep 你有解决这个错误的办法吗?
标签: ruby-on-rails-4 rubygems intuit-partner-platform quickbooks-online intuit