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.
Related
I am using jekyll for the first time.
I downloaded the source code from here. When i run build and run the site using jekyll it runs well. Now I downloaded personal theme from here. After navigating to the downloaded themes folder and then building the new theme doesn't work. I get the following error :
Configuration file: /home/repos/sites/personal-jekyll-theme/_config.yml
/usr/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- jemoji (LoadError)
from /usr/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /usr/lib/ruby/vendor_ruby/jekyll/plugin_manager.rb:28:in `block in require_gems'
from /usr/lib/ruby/vendor_ruby/jekyll/plugin_manager.rb:26:in `each'
from /usr/lib/ruby/vendor_ruby/jekyll/plugin_manager.rb:26:in `require_gems'
from /usr/lib/ruby/vendor_ruby/jekyll/plugin_manager.rb:19:in `conscientious_require'
from /usr/lib/ruby/vendor_ruby/jekyll/site.rb:71:in `setup'
from /usr/lib/ruby/vendor_ruby/jekyll/site.rb:33:in `initialize'
from /usr/lib/ruby/vendor_ruby/jekyll/commands/build.rb:28:in `new'
from /usr/lib/ruby/vendor_ruby/jekyll/commands/build.rb:28:in `process'
from /usr/lib/ruby/vendor_ruby/jekyll/commands/build.rb:17:in `block (2 levels) in init_with_program'
from /usr/lib/ruby/vendor_ruby/mercenary/command.rb:220:in `call'
from /usr/lib/ruby/vendor_ruby/mercenary/command.rb:220:in `block in execute'
from /usr/lib/ruby/vendor_ruby/mercenary/command.rb:220:in `each'
from /usr/lib/ruby/vendor_ruby/mercenary/command.rb:220:in `execute'
from /usr/lib/ruby/vendor_ruby/mercenary/program.rb:42:in `go'
from /usr/lib/ruby/vendor_ruby/mercenary.rb:19:in `program'
from /usr/bin/jekyll:18:in `<main>'
Ruby Verison : ruby 2.1.5p273 (2014-11-13) [x86_64-linux-gnu]
Jekyll Version : jekyll 2.2.0
If possible please let me know where and what I am doing wrong. Is there some rule which states that I can locally build only one rule ? As far as I searched I tried changing the port number in config.yml and also tried building different sites with specifying their respective config files. jekyll still doesn't build and gives the same error. Thanks for your help in advance.
I also get the error which is jekyll-feed Load Error
The above issue was resolved following the instructions in readme file and running ./scripts/install.
Thanks #Jordan for your help.
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.
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.
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.
I am simply requiring a file present in the same folder as the testfile however I am getting this wierd message again and again...
<internal:lib/rubygems/custom_require>:29:in `require': no such file to load -- a.rb (LoadError)
from <internal:lib/rubygems/custom_require>:29:in `require'
from C:/dummyFirefox/test_a.rb:1:in `<top (required)>'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:386:in `load'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:386:in `block in load_spec_files'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:386:in `map'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:386:in `load_spec_files'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.5.1/lib/rspec/core/command_line.rb:18:in `run'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.5.1/lib/rspec/core/runner.rb:55:in `run_in_process'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.5.1/lib/rspec/core/runner.rb:46:in `run'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.5.1/lib/rspec/core/runner.rb:10:in `block in autorun'
the code that I write in my testfile test_a.rb is simply:
require 'a.rb'
and when I issue the command : rspec test_a.rb the message is the above mentioned error.
I am using ruby-1.9.2 for development.
Hope I don't miss any details.
Thanks in advance.
In Ruby 1.9.2 the current working directory is no longer part of the load path ($LOAD_PATH or $:). You have to add it manually using:
$LOAD_PATH.unshift '.'
or
$:.unshift '.'
Or you can require the file explicitly:
require './test_a.rb'