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"
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.
Related
I have a brand new Rails 6 app and without anything in the config/routes.rb, the output of bin/rails routes has a massive list of very long urls for ActiveStorage, Action Mailbox, and conductor.
This is making bin/rails routes completely useless as a form of documentation, especially since the options for bin/rails routes don't allow filtering out things.
I don't want to omit these parts of Rails as I may need them. But I would prefer these routes a) not exist if I'm not using them and b) not show up in bin/rails routes.
Does anyone know how to make this work?
As of Rails 6.0.2.1, this is the way to do it:
In config/application.rb, remove the line require "rails/all" and replace it with this:
# See https://github.com/rails/rails/blob/v6.0.2.1/railties/lib/rails/all.rb for the list
# of what is being included here
require "rails"
# This list is here as documentation only - it's not used
omitted = %w(
active_storage/engine
action_cable/engine
action_mailbox/engine
action_text/engine
)
# Only the frameworks in Rails that do not pollute our routes
%w(
active_record/railtie
action_controller/railtie
action_view/railtie
action_mailer/railtie
active_job/railtie
rails/test_unit/railtie
sprockets/railtie
).each do |railtie|
begin
require railtie
rescue LoadError
end
end
Note that if you leave actiontext in, you still get a few active storage routes included. Not sure why. This configuration basically means you cannot use active storage, action text, or action mailbox. Bringing those back in will bring back many routes you will never need.
Also note this solution has a carrying cost because with each Rails version upgrade, you must examine rails/all.rb to make sure no new frameworks were added that you might care about (or removed that you no longer should be requiring).
You can have the ActionMailbox routes omitted by commenting out the specific require line in your application.rb.
Specifically if you comment the require "action_mailbox/engine" line you'll no longer see any of the /rails/action_mailbox or /rails/conductor/action_mailbox routes.
You'll need to restart the app for the changes to take affect.
I set up a Rails app on OpenShift and pulled the default code. When I tried running it, I got the following error:
C:/Development/Ruby/lib/ruby/gems/2.3.0/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:241:in `load': C:/HEATH3N/FirstApp/config/initializers/session_store.rb:1: syntax error, unexpected .. (SyntaxError)
../../.openshift/lib/session_store.rb
I'm unclear as to what the problem is. I looked at the problematic file and don't see anything wrong. I found other questions on Stack Overflow asking about another problem with the file (the new hash style isn't supported on older Ruby versions) but I'm using Ruby 2.3 (Rails 4.1.4) and my error is different.
require File.join(Rails.root,'lib','openshift_secret_generator.rb')
# Be sure to restart your server when you modify this file.
# Set token based on intialize_secret function (defined in initializers/secret_generator.rb)
Rails.application.config.session_store :cookie_store, :key => initialize_secret(
:session_store,
'_railsapp_session'
)
# Use the database for sessions instead of the cookie-based default,
# which shouldn't be used to store highly confidential information
# (create the session table with "rails generate session_migration")
# RailsApp::Application.config.session_store :active_record_store
Try something like so -
require File.expand_path(‘../lib/openshift_secret_generator.rb‘, __FILE__)
or
require Rails.root.join('lib', 'openshift_secret_generator.rb').to_s
Please do update if either or both work for you.
I have set up Facebook login on my site following this tutorial and am using cucumber and capybara. I have tried following other SO posts like this that explain how to set up a fake login account. If I use this directly, I get:
When I follow "sign_in" # features/step_definitions/web_steps.rb:56
No route matches [GET] "/oauth/authorize" (ActionController::RoutingError)
./features/step_definitions/web_steps.rb:57:in `/^(?:|I )follow "([^"]*)"$/'
features/facebook_signin.feature:9:in `When I follow "sign_in"'
If I add get "/oauth/authorize" to my routes, I get:
When I follow "sign_in" # features/step_definitions/web_steps.rb:56
uninitialized constant OauthController (ActionController::RoutingError)
./features/step_definitions/web_steps.rb:57:in `/^(?:|I )follow "([^"]*)"$/'
features/facebook_signin.feature:9:in `When I follow "sign_in"'
I don't know what is going on and why it is complaining. If I change my Gemfile from gem 'omniauth-facebook', '1.4.0' to just gem 'omniauth-facebook' I get virtually the same errors above except instead of:
/oauth/authorize, I get /dialog/oauth and instead of uninitialized constant OauthController, I get uninitialized constant DialogController
Has anyone recently successfully set up cucumber testing for login with Facebook?
When I am on localhost:3000 and navigate to localhost:3000/auth/facebook everything works and I am using a sessionsController so I don't understand why in testing, it is trying to use these oauthControllers or DialogueControllers.
I recently had the same issue or a very similar issue:
ActionController::RoutingError:
No route matches [GET] "/dialog/oauth"
I had taken the working specs which properly set up mock responses from another project and was pretty surprised to suddenly get this error.
After much pain and suffering I had a major facepalm moment when I realized i had forgot to set OmniAuth to use test mode:
# spec/rails_helper.rb
OmniAuth.config.test_mode = true
This will cause OmniAuth to short circuit so that you can set the auth responses by:
OmniAuth.config.mock_auth[:facebook] = OmniAuth::AuthHash.new({
:provider => 'facebook',
:uid => '123545'
# etc.
})
I think the error is due to OmniAuth trying to be helpful by using the :developer strategy in the test environment so that you don't get banned by the auth provider.
See https://github.com/intridea/omniauth/wiki/Integration-Testing.
Have you enabled Javascript in this tests? As the tutorial mentions the facebook.js.coffee?
describe 'When I follow "sign in"', js: true do
Another possibility is that you included the gem only in the development block of the Gemfile
group :development do
gem 'omniauth-facebook'
end
BTW: you shouldn't be testing against "real" external endpoints. Take a look at webmock for this kind of tests to mock the Facebook response
I had to put #omniauth_test_success before the feature and not the step definition. Additionally, I had to fix some routing issues. Will post full report later this week.
General problem. Working on a ROR app hosted on Heroku. However I am getting the error in local environment. For Articles I wish users to be able to "recommend" the article via Facebook and display number of "recommends" the Article has recieved.
I have a ROR application on Heroku and have set up a Facebook app with minimum info.
Where/how do I add in the Facebook info he ROR application.
I have tried a number of different things including
(1) adding some info to config/environment/development e.g.
# Facebook stuff
config.fb_app_id = 257669251071656
config.fb_app_secret = 7b53604575d5dc0259466cfd41808c93
which gives error
/Users/davidlee/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.4/lib/active_support/dependencies.rb:229:in `require': /Volumes/F Drive/drill_investor/config/environments/development.rb:49: syntax error, unexpected tIDENTIFIER, expecting keyword_end (SyntaxError)
Should I be adding a config/initializers/facebook.rb file and/or changes in config/environments/development…production. If so what goes into the onfig/initializers/facebook.rb file ?
At the moment I have some stuff set up for devise and paperclip in these directories - however this was all copied and haven't figured out how it actually works.
any help appreciated
Pierre
The new whole config/application.rb file, with comments removed, is below
require File.expand_path('../boot', __FILE__)
require 'rails/all'
Bundler.require(:default, Rails.env)
module DrillInvestor
class Application < Rails::Application
# pmlc
ActsAsTaggableOn.force_lowercase = true
ActsAsTaggableOn.remove_unused_tags = true
config.fb_app_id = ENV["FACEBOOK_APP"]
config.fb_app_secret = ENV["FACEBOOK_SECRET"]
# pmlc
end
end
The environment files of Rails are meant to give you a place to specific environment-specific settings -- such as different asset paths, Gem settings, etc to use
Error
Your error basically says your development.rbfile is not formatted correctly (you should post the whole file). You'll need to be able to set it out correctly - I'd even recommend putting the details into application.rb:
#config/application.rb
config.fb_app_id = ENV["FACEBOOK_APP"]
config.fb_app_secret = ENV["FACEBOOK_SECRET"]
#config/application.yml -> from Figaro
FACEBOOK_APP: 257669251071656
FACEBOOK_SECRET: 7b53604575d5dc0259466cfd41808c93
Figaro
I'd recommend using Figaro to keep your sensitive data behind closed doors. It allows you to create environment variables on both local & production environments
I think this should solve your issue, but it will definitely help to post your development.rb
I have the simple following code, which is working in a ruby (not rails) app:
require 'gmail'
Gmail.new('my_account', 'my_password') do |gmail|
end
I am able to get a connection to the Gmail account and do some stuff in there.
However, I want to use this Gem in a Rails app, and therefore I have tried adding the following into the Gemfile:
gem "ruby-gmail", "0.2.1"
gem "mime", "0.1"
However, when I try to use this in a rake task, like this:
task :scrap_receipts_gmail => :environment do
Gmail.new('my_account', 'my_password') do |gmail|
puts gmail.inspect
end
end
I get the following error:
uninitialized constant Object::Gmail
This is solved if I add require 'gmail'. My question is:
Why would I have to require gmail, if I have already specified that in the Gemfile?
The module/class namespace has to match the directory structure. For example, in lib/foo/bar.rb, if and only if the namespace is Foo::Bar can it be auto loaded by Rails, otherwise you have to require it explicitly.
In this case, Gmail is defined as a class, which doesn't match the directory structure. If Gmail was defined as a module (namespace ::Gmail matchs directory structure), then you'll never need to explicitly require "gmail".