LoadError: cannot load such file -- omniauth-twitter - ruby

I'm trying to get OAuth2 working for my Sinatra app via OmniAuth but receive:
LoadError: cannot load such file -- omniauth-twitter
I'm following these examples, though they're a bit inconsistent
- http://recipes.sinatrarb.com/p/middleware/twitter_authentication_with_omniauth
app.rb
- https://github.com/intridea/omniauth/wiki/Sinatra-Example
The Sinatra Recipe tells me to put the builder within 'configure do' while the official example doesn't, but has 'use Rack::Session::Cookie'
I've scoured the net looking for good Sinatra OmniAuth examples, but it seems it favors Rails.
require "omniauth"
require "omniauth-twitter"
# OAuth2 configuration
use Rack::Session::Cookie
use OmniAuth::Builder do
provider :twitter, 'CONSUMER_KEY', 'CONSUMER_SECRET'
end
before do
# we do not want to redirect to twitter when the path info starts
# with /auth/
pass if request.path_info =~ /^\/auth\//
# /auth/twitter is captured by omniauth:
# when the path info matches /auth/twitter, omniauth will redirect to twitter
redirect to('/auth/twitter') unless current_user
end
get '/auth/twitter/callback' do
# probably you will need to create a user in the database too...
session[:uid] = env['omniauth.auth']['uid']
# this is the main endpoint to your application
redirect to('/')
end
get '/twitter' do
erb "<a href='/auth/twitter'>Sign in with Twitter</a>"
end
# Support for OAuth failure
get '/auth/failure' do
flash[:notice] = params[:message] # if using sinatra-flash or rack-flash
redirect '/'
end
The full error I get
Boot Error
Something went wrong while loading config.ru
LoadError: cannot load such file -- omniauth-twitter /usr/local/rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `require'
/usr/local/rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `block in require'
/usr/local/rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:236:in `load_dependency'
/usr/local/rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `require'
/Users/chadsakonchick/Projects/restlessnapkin/app.rb:11:in `<top (required)>'
config.ru:1:in `require'
config.ru:1:in `block in inner_app'
/usr/local/rvm/gems/ruby-1.9.3-p194/gems/rack-1.5.2/lib/rack/builder.rb:55:in `instance_eval'
/usr/local/rvm/gems/ruby-1.9.3-p194/gems/rack-1.5.2/lib/rack/builder.rb:55:in `initialize'
config.ru:1:in `new'
config.ru:1:in `inner_app'
/usr/local/rvm/gems/ruby-1.9.3-p194/gems/shotgun-0.9/lib/shotgun/loader.rb:112:in `eval'
/usr/local/rvm/gems/ruby-1.9.3-p194/gems/shotgun-0.9/lib/shotgun/loader.rb:112:in `inner_app'
/usr/local/rvm/gems/ruby-1.9.3-p194/gems/shotgun-0.9/lib/shotgun/loader.rb:102:in `assemble_app'
/usr/local/rvm/gems/ruby-1.9.3-p194/gems/shotgun-0.9/lib/shotgun/loader.rb:86:in `proceed_as_child'
/usr/local/rvm/gems/ruby-1.9.3-p194/gems/shotgun-0.9/lib/shotgun/loader.rb:31:in `call!'
/usr/local/rvm/gems/ruby-1.9.3-p194/gems/shotgun-0.9/lib/shotgun/loader.rb:18:in `call'
/usr/local/rvm/gems/ruby-1.9.3-p194/gems/shotgun-0.9/lib/shotgun/favicon.rb:12:in `call'
/usr/local/rvm/gems/ruby-1.9.3-p194/gems/rack-1.5.2/lib/rack/builder.rb:138:in `call'
/usr/local/rvm/gems/ruby-1.9.3-p194/gems/rack-1.5.2/lib/rack/handler/webrick.rb:60:in `service'
/usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
/usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
/usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'

Shotgun was the culprit. Works fine when I run 'ruby app.rb' from the terminal, but with shotgun I receive the error.

It looks like the omniauth-twitter gem isn't installed. For example:
> require "blahblahblah"
LoadError: cannot load such file -- blahblahblah
You need to gem install omniauth-twitter, include it in your gemspec if you're using bundler, or whatever makes sense in you project.

Related

NoMethodError: undefined method `ignore' for Warning:Module

I am unable to find any explanation for this error but when I am running:
rake test or bundle exec rake test I am getting:
NoMethodError: undefined method `ignore' for Warning:Module
/Users/przemyslaw/projects/writefully/config/initializers/warning.rb:4:in `block in <top (required)>'
/Users/przemyslaw/projects/writefully/config/initializers/warning.rb:3:in `each'
/Users/przemyslaw/projects/writefully/config/initializers/warning.rb:3:in `<top (required)>'
/Users/przemyslaw/projects/writefully/config/environment.rb:5:in `<top (required)>'
/Users/przemyslaw/projects/writefully/test/test_helper.rb:2:in `require'
/Users/przemyslaw/projects/writefully/test/test_helper.rb:2:in `<top (required)>'
/Users/przemyslaw/projects/writefully/test/controllers/comments_controller_test.rb:1:in `require'
/Users/przemyslaw/projects/writefully/test/controllers/comments_controller_test.rb:1:in `<top (required)>'
Tasks: TOP => test:run
(See full trace by running task with --trace)
I am following a tutorial on codemy.net and there is nothing complicated or special about this project. I have only generated a new rails app, a couple of models and controllers and now when I am trying to run the test it gives me this error. There is no single test within my test files at the moment so this is nothing to do with testing. It looks like there is some issue with the 'ignore' method within the warning file:
config/initializers/warning.rb
# Rails will load this logic before booting up Rails server
unless Rails.env.development?
Gem.path.each do |path|
Warning.ignore(//, path)
end
end
Any help or idea would be appreciated. I am using rails 4.2.10 and ruby 2.5.8.
Seems like you missed installing the warning gem.
I suggest adding the line
gem "warning"
to your Gemfile and run bundler before restarting your application.

Deploying rails app Capistrano plenty ERRORS

i am trying to deploy my rails application for the first time on vexxhost. i am using github as my Source code management and capistrano.
here is my deploy file
require 'bundler/capistrano'
require 'capistrano'
require 'bundler'
require 'capistrano-vexxhost'
# Account Settings
ssh_options[:forward_agent] = true
set :scm_command, "/home/user/opt/bin/git"
set :local_scm_command,"git"
set :user, "xxxxxxxx"
set :password, "xxxxxxxxx"
set :domain, "domain.com"
set :mount_path,"/home/xxxxxxxx/xxxxxxx"
set :application,"app name"
set :scm, :git
set :deploy_via, :copy
set :repository, "git#github.com:xxxxx/xxxxxxx.git"
default_run_options[:pty] = true
PROBLEM NO 1)
As soon as i installed gem 'capistrano' gem 'capistrano-vexxhost' i got the following error when trying to run my application locally (it was working before installing capistrano).
C:/Ruby193/lib/ruby/gems/1.9.1/gems/capistrano-2.14.1/lib/capistrano/configuration/loading.rb:18:in `instance': Please require this file from within a Capistrano recipe (LoadError)
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/capistrano-vexxhost-1.0.3/lib/capistrano-vexxhost/capistrano_integration.rb:6:in `<top (required)>'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/capistrano-vexxhost-1.0.3/lib/capistrano-vexxhost.rb:2:in `require'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/capistrano-vexxhost-1.0.3/lib/capistrano-vexxhost.rb:2:in `<top (required)>'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.2.3/lib/bundler/runtime.rb:68:in `require'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.2.3/lib/bundler/runtime.rb:68:in `block (2 levels) in require'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.2.3/lib/bundler/runtime.rb:66:in `each'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.2.3/lib/bundler/runtime.rb:66:in `block in require'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.2.3/lib/bundler/runtime.rb:55:in `each'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.2.3/lib/bundler/runtime.rb:55:in `require'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.2.3/lib/bundler.rb:128:in `require'
from C:/Users/mummy/LagoAds/config/application.rb:9:in `<top (required)>'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.2.6/lib/rails/commands.rb:53:in `require'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.2.6/lib/rails/commands.rb:53:in `block in <top (required)>'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.2.6/lib/rails/commands.rb:50:in `tap'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.2.6/lib/rails/commands.rb:50:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
NOTE But as i soon as i comment the Bundler.require line from the following code in the application.rb file, it successfully runs but doesn't recognize the gems
if defined?(Bundler)
# If you precompile assets before deploying to production, use this line
Bundler.require(*Rails.groups(:assets => %w(development test)))
# If you want your assets lazily compiled in production, use this line
# Bundler.require(:default, :assets, Rails.env)
end
PROBLEM NO 2)
when is type "cap deploy:check" on my ruby command prompt i the get the following error.
PROBLEM NO 3)
when is type "cap deploy:cold" on my ruby command prompt i get the following error
Is there anything missing from my deploy.rb or is there anything i didnt do.
PLEASE I NEED HELP, I HAVE BEEN ON THIS PROBLEM FOR VERY LONG TIME. I AM NEW TO DEPLOYING WEB APPLICATIONS AND RAILS HAVE BEEN VERY DIFFICULT FOR ME
PLEASE HELP
Problems 2 & 3
Your second and third problems are the result of git and tar not being in your path. Either they are not installed at all, or your path is incomplete. See the errors I quoted below.
problem 2
'git' could not be found on the local host
'tar' could not be found on the local host
problem 3
no such file or directory git ls-remote...
Problem 1
Unfortunately I have no answer for #1. A guess would be that you need to add capistrano and/or capistrano-vexxhost to your deploy.rb.

Ruby `require` call fails on custom code

I have found that I have no problem using require to load something like the Sinatra web framework, but I can't seem to use require to load my own custom code?
For example I have two files:
test1.rb
test2.rb
The content of 'test1.rb' is:
#!/usr/bin/env ruby
require 'test2'
The content of 'test2.rb' is:
class String
def vowels
self.scan(/[aeiou]/i)
end
end
And if I try and run ruby test1.rb then I get the following error...
/Users/<username>/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- test2 (LoadError)
from /Users/<username>/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from test1.rb:3:in `<main>'
I then noticed if I tried to use the shotgun gem to load the web server then I get a different but more detailed stack trace of the error...
Boot Error
Something went wrong while loading test1.rb
LoadError: cannot load such file -- test2
/Users/<username>/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
/Users/<username>/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
/Users/<username>/Dropbox/Library/Ruby/Passage/test1.rb:3:in `<top (required)>'
/Users/<username>/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
/Users/<username>/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
/Users/<username>/.rvm/gems/ruby-1.9.3-p125/gems/shotgun-0.9/lib/shotgun/loader.rb:114:in `inner_app'
/Users/<username>/.rvm/gems/ruby-1.9.3-p125/gems/shotgun-0.9/lib/shotgun/loader.rb:102:in `assemble_app'
/Users/<username>/.rvm/gems/ruby-1.9.3-p125/gems/shotgun-0.9/lib/shotgun/loader.rb:86:in `proceed_as_child'
/Users/<username>/.rvm/gems/ruby-1.9.3-p125/gems/shotgun-0.9/lib/shotgun/loader.rb:31:in `call!'
/Users/<username>/.rvm/gems/ruby-1.9.3-p125/gems/shotgun-0.9/lib/shotgun/loader.rb:18:in `call'
/Users/<username>/.rvm/gems/ruby-1.9.3-p125/gems/shotgun-0.9/lib/shotgun/favicon.rb:12:in `call'
/Users/<username>/.rvm/gems/ruby-1.9.3-p125/gems/shotgun-0.9/lib/shotgun/static.rb:14:in `call'
/Users/<username>/.rvm/gems/ruby-1.9.3-p125/gems/rack-1.4.1/lib/rack/builder.rb:134:in `call'
/Users/<username>/.rvm/gems/ruby-1.9.3-p125/gems/thin-1.3.1/lib/thin/connection.rb:80:in `block in pre_process'
/Users/<username>/.rvm/gems/ruby-1.9.3-p125/gems/thin-1.3.1/lib/thin/connection.rb:78:in `catch'
/Users/<username>/.rvm/gems/ruby-1.9.3-p125/gems/thin-1.3.1/lib/thin/connection.rb:78:in `pre_process'
/Users/<username>/.rvm/gems/ruby-1.9.3-p125/gems/thin-1.3.1/lib/thin/connection.rb:53:in `process'
/Users/<username>/.rvm/gems/ruby-1.9.3-p125/gems/thin-1.3.1/lib/thin/connection.rb:38:in `receive_data'
/Users/<username>/.rvm/gems/ruby-1.9.3-p125/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in `run_machine'
/Users/<username>/.rvm/gems/ruby-1.9.3-p125/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in `run'
/Users/<username>/.rvm/gems/ruby-1.9.3-p125/gems/thin-1.3.1/lib/thin/backends/base.rb:61:in `start'
/Users/<username>/.rvm/gems/ruby-1.9.3-p125/gems/thin-1.3.1/lib/thin/server.rb:159:in `start'
/Users/<username>/.rvm/gems/ruby-1.9.3-p125/gems/rack-1.4.1/lib/rack/handler/thin.rb:13:in `run'
/Users/<username>/.rvm/gems/ruby-1.9.3-p125/gems/shotgun-0.9/bin/shotgun:156:in `<top (required)>'
/Users/<username>/.rvm/gems/ruby-1.9.3-p125/bin/shotgun:19:in `load'
/Users/<username>/.rvm/gems/ruby-1.9.3-p125/bin/shotgun:19:in `<main>'
/Users/<username>/.rvm/gems/ruby-1.9.3-p125/bin/ruby_noexec_wrapper:14:in `eval'
/Users/<username>/.rvm/gems/ruby-1.9.3-p125/bin/ruby_noexec_wrapper:14:in `<main>'
I'm not sure what the problem is?
Any help appreciated please.
Thanks.
The current directory (relative to the main ruby file) is not part of the load paths (the set of paths that require looks in). So you either need to add it to the load path (best done by invoking ruby as ruby -I. test1.rb), by using require "./test2.rb" or by using require_relative "test2.rb", which requires files relative to the directory of the file.

Problems with Sinatra + Mustache in OSX Lion

I am trying to get up and running with Sinatra and Mustache in OSX Lion. After a lot of googling around I am no further in fixing the issue. I am pretty sure it has to do with Ruby permissions in OSX because the error (below) starts with the first line of the example config.ru file (require 'app'). The project is here ( https://github.com/defunkt/mustache-sinatra-example)
here is my error
Boot Error
Something went wrong while loading config.ru
LoadError: no such file to load -- app
/Users/ghostandthemachine/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
/Users/ghostandthemachine/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
config.ru:1:in `block in inner_app'
/Users/ghostandthemachine/.rvm/gems/ruby-1.9.2-p290/gems/rack-1.3.1/lib/rack/builder.rb:51:in `instance_eval'
/Users/ghostandthemachine/.rvm/gems/ruby-1.9.2-p290/gems/rack-1.3.1/lib/rack/builder.rb:51:in `initialize'
config.ru:1:in `new'
config.ru:1:in `inner_app'
/Users/ghostandthemachine/.rvm/gems/ruby-1.9.2-p290/gems/shotgun-0.9/lib/shotgun/loader.rb:112:in `eval'
/Users/ghostandthemachine/.rvm/gems/ruby-1.9.2-p290/gems/shotgun-0.9/lib/shotgun/loader.rb:112:in `inner_app'
/Users/ghostandthemachine/.rvm/gems/ruby-1.9.2-p290/gems/shotgun-0.9/lib/shotgun/loader.rb:102:in `assemble_app'
/Users/ghostandthemachine/.rvm/gems/ruby-1.9.2-p290/gems/shotgun-0.9/lib/shotgun/loader.rb:86:in `proceed_as_child'
/Users/ghostandthemachine/.rvm/gems/ruby-1.9.2-p290/gems/shotgun-0.9/lib/shotgun/loader.rb:31:in `call!'
/Users/ghostandthemachine/.rvm/gems/ruby-1.9.2-p290/gems/shotgun-0.9/lib/shotgun/loader.rb:18:in `call'
/Users/ghostandthemachine/.rvm/gems/ruby-1.9.2-p290/gems/shotgun-0.9/lib/shotgun/favicon.rb:12:in `call'
/Users/ghostandthemachine/.rvm/gems/ruby-1.9.2-p290/gems/rack-1.3.1/lib/rack/builder.rb:134:in `call'
/Users/ghostandthemachine/.rvm/gems/ruby-1.9.2-p290/gems/rack-1.3.1/lib/rack/handler/webrick.rb:59:in `service'
/Users/ghostandthemachine/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service'
/Users/ghostandthemachine/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run'
/Users/ghostandthemachine/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'
any help would be much appreciated. Thanks in advance
In ruby 1.9.2 current dir isn't searched for required files, so you should specify path
require './app'
Similarly, in app.rb you will need to change
6 require 'views/layout' to require './views/layout'
and
9 :views => 'views', to :views => './views',
Change the line
require 'app'
to
require './app'
It looks like you're using Ruby 1.9.2. The current directory was removed from Ruby's load path in this version, so require 'app' no longer works, you need to specify that the file is in the current directory with require './app'. I assume that example project was built using an earlier version of Ruby.

How to deploy rack apps with ruby1.9?

I've been trying to get a simple hello world web app running on Sinatra.
I have the following setup:
config.ru
require 'hello.rb'
run Sinatra::Application
hello.rb
require "sinatra"
get "/" do
"Hello World!\n"
end
Gemfile
source :rubygems
gem 'sinatra'
This works on my local machine if I run ruby hello.rb, ruby1.9.1 hello.rb or rackup and go to the correct address in my browser. However, this doesn't work when deployed to heroku or if I run rackup1.9.1. I get the following error:
<internal:lib/rubygems/custom_require>:29:in `require': no such file to load -- hello.rb (LoadError)
from <internal:lib/rubygems/custom_require>:29:in `require'
from config.ru:1:in `block in <main>'
from /usr/lib/ruby/1.9.1/rack/builder.rb:46:in `instance_eval'
from /usr/lib/ruby/1.9.1/rack/builder.rb:46:in `initialize'
from config.ru:1:in `new'
from config.ru:1:in `<main>'
from /usr/lib/ruby/1.9.1/rack/builder.rb:35:in `eval'
from /usr/lib/ruby/1.9.1/rack/builder.rb:35:in `parse_file'
from /usr/lib/ruby/1.9.1/rack/server.rb:113:in `app'
from /usr/lib/ruby/1.9.1/rack/server.rb:189:in `wrapped_app'
from /usr/lib/ruby/1.9.1/rack/server.rb:155:in `start'
from /usr/lib/ruby/1.9.1/rack/server.rb:83:in `start'
from /usr/bin/rackup1.9.1:4:in `<main>'
How can I get this working? I'm guessing config.ru should be different but I don't know what to change.
Try doing
require './hello'
or
require_relative 'hello'
The current directory is not present in the LOAD_PATH by default in Ruby 1.9.2.

Resources