I have a sinatra app which runs on
ruby 1.9.3-p327with gemset exampleGemset (.rvmrc file)
when I run
bundle exec gem list
I get the gem
friendlyfashion-graylog2_exceptions (1.3.2)
but when I try to require it with require 'graylog2_exceptions' I get this error
LoadError: cannot load such file -- graylog2_exceptions
any ideas??
the problem was resloved by using the gem graylog2_exceptions
simply gem install graylog2_exceptions did the trick
Related
I'm trying to run a Sinatra application with the most basic app.rb:
require 'sinatra/activerecord/rake'
require 'bundler/setup'
Bundler.require(:default)
require_relative './config'
require_relative './models/star'
require_relative './models/planet'
require_relative './models/moon'
require_relative './models/astronaut'
get '/' do
erb :index
end
After using Bundle and creating Gemfile.lock I'm keep getting this error:
You have already activated activesupport 4.0.2, but your Gemfile requires activesupport 3.2.16. Using bundle exec may solve this. (Gem::LoadError)
My Rakefile is:
source 'https://rubygems.org'
gem 'sinatra'
gem 'sinatra-reloader'
gem 'sinatra-activerecord'
gem 'activerecord', '~> 3.2.13'
gem 'rake'
gem 'pg'
gem 'pry'
I'll be grateful for any suggestions.
You have both ActiveRecord 4.0.2 and 3.2.13 installed on your system. The first line of your app requires sinatra/activerecord/rake which in turn requires activerecord, without specifying which version. This activates and loads 4.0.2 – the latest version.
In the next line you try to set up Bundler. Bundler now tries to activate version 3.2.13 of ActiveRecord as specified in your Gemfile, but can’t since a version is already activated, so you get an error.
To fix, simply make sure you call require 'bundler/setup' first, before you require any other files. This will ensure any files you require will be compatible with your Gemfile.
Alternatively you could remove the call to require bundler/setup and make sure you always start your app using bundle exec.
I am getting a ruby error when an app I am running tries to…
require "xcodeproj/xcodeproj_ext" (https://github.com/CocoaPods/Xcodeproj)
The gem has been installed in /Library/Ruby/Gems/1.8/gems/xcodeproj-0.5.5.
gem list xcodeproj outputs the following...
xcodeproj (0.5.5, 0.5.0, 0.4.3, 0.3.4, 0.3.1, 0.1.0)
There is no xcodeproj_ext file or directory. What is it looking for?
How do I best go about debugging this?
UPDATE: The app that I am trying to running is using http://gembundler.com/
Are you able to require any other gems? Try doing:
require 'rubygems'
require 'xcodeproj'
It seems something was missing in the installed gem.
After removing the ~/.bundler folder and running bundle install again it worked as expected.
I need to reference a local gem from a plain ruby script, without installing the gem. On the trail of How to refer a local gem in ruby?, i tried creating a Gemfile with the following setup:
%w(
custom_gem
another_custom_gem
).each do |dependency|
gem dependency, :path => File.expand_path("../../#{dependency}", __FILE__)
end
and the script looks like this:
require 'custom_gem'
CustomGem::Do.something
When I execute this with:
bundle exec ruby script.rb
I get:
script.rb:1:in `require': cannot load such file -- custom_gem (LoadError) from script.rb:1:in `<main>'
If I leave out the require 'custom_gem' , I get:
script.rb:3:in `<main>': uninitialized constant CustomGem (NameError)
I even tried without bundler, and just writing gem ... :path =>̣ ... in the script itself, but without results. Is there any other way of referencing custom gems from ruby scripts, without installing the gems locally?
Make sure that your gem name as same as in Gemfile (e.g. custom_gem)
# Gemfile
source "https://rubygems.org"
gem "custom_gem", path: "/home/username/path/to/custom_gem"
Don't forget to actually install this gem using bundler
bundle install
After that, the script should be ready to use by bundle exec ruby script.rb
# script.rb
require 'custom_gem'
CustomGem::Do.something
Without using a Gemfile, you can install a local version of a gem by running bundle exec rake install in the gem's root directory and then you can reference it just like any other installed gem.
I'm trying to build an app using Sinatra, Ruby, rack, haml, pony and SendGrid, with git and RVM for deployment on Heroku. The app is a blog variant that should send out an email with commentary submitted on a form. On my local server, when the form submits I get the following error:
LoadError at /
cannot load such file -- pony
file: tools.rb location: require line: 314
BACKTRACE
(expand)
/Users/Kevin/prog/ruby/Sinatra/Noobs/noobs.rb in block in <top (required)>
require 'pony'
When run on Heroku, form submittal results in an internal server error. The 'cannot load such file' error suggests that the file is not on the gem path, but if I understand correctly, the OS disagrees:
➜ noobs git:(master) ✗ bundle show pony
/Users/Kevin/.rvm/gems/ruby-1.9.3-p194#noobs/gems/pony-1.4
➜ noobs git:(master) echo $GEM_PATH
/Users/Kevin/.rvm/gems/ruby-1.9.3-p194#noobs:/Users/Kevin/.rvm/gems/ruby-1.9.3-p194#global
Here is the code where pony is required (noobs.rb):
require 'rubygems'
require 'sinatra'
require 'haml'
require "sinatra/reloader" if development?
# ...
post '/' do
require 'pony'
Pony.mail(:from => params[:name] + "<" + params[:contact] + ">",
What do I need to do to get pony to work?
require "bundler/setup"
Will probably fix your error.
Since you are using Bundler with Sinatra you need to require Bundler for the bundled gems to work. You probably have your gems split between Bundler and your gemset. If you have Sinatra and Haml in your gemset but Pony in your Gemfile you will see a LoadError.
I write down name of the gem (pony - in my case) in Gemfile - and it starts to work.
Just open Jemfile - and write down words jem "pony" in the new line I get the following paste2.org/6hVxHXKH
I am having trouble configuring Sinatra to use Bundler. I am confused as to where Gems should be being installed? I've read both this question and this documentation.
My Gemfile looks like:
source "http://rubygems.org"
gem "sinatra"
gem "amazon-ec2"
My config.ru looks like:
require "rubygems"
require "bundler"
Bundler.setup
require "application"
run Sinatra::Application
My application.rb looks like:
require "rubygems"
require "sinatra"
require "AWS"
#... rest of application
Now, when I run bundle install everything works correctly and Gems get installed into ~/.bundle/ in my home directory. Yet, in my app if I have a look at .bundle/config it shows:
---
BUNDLE_WITHOUT: ""
BUNDLE_PATH: vendor/gems
Sure enough, when I start up the app (using Passenger by the way) it says:
Could not find gem 'amazon-ec2 (>= 0, runtime)' in the gems available on this machine. (Bundler::GemNotFound)
Clearly bundle install is installing Gems in a different place to where Sinatra expects them to be. Does that mean I have to use bundle install vendor or reconfigure something else so that the application expects the Gems to be in ~/.bundle?
About a year after #aaronrussell 's initial posting, I hit the same problem with Passenger, Nginx, Bundler, Sinatra. I got through it by running this on production:
bundle install --deployment
Bundled gems go in ./vendor/bundle
Here are some details on bundler deployment mode