I'm trying to deploy an app in Openshift that requires some gems, how do I get Openshift to install those when I push via git?
Here's what my config.ru file currently looks like:
require 'rubygems'
require './app.rb'
run Sinatra::Application
And as for app.rb it requires the following gems:
require 'sinatra'
require 'redcarpet'
require 'stringex'
require 'data_uri'
Any ideas what I'm doing wrong here? Thanks in advance!
You probabily need to add those into a Gemfile like:
# Gemfile
source 'http://rubygems.org'
gem 'sinatra'
gem 'redcarpet'
gem 'stringex'
gem 'data_uri'
and run bundle locally before pushing to generate the Gemfile.lock
Use Bundler for you app
in Gemfile
gem 'sinatra'
gem 'redcarpet'
gem 'stringex'
gem 'data_uri'
in config.ru
require 'rubygems'
require 'bundler'
Bundler.require
require './my_app'
run Sinatra::Application
Start server with rackup, and Sinatra will be loaded via Bundler.
$ rackup
Related
im developing a application in ruby with sinatra. evrything worked finely until i put it on heroku. heroku gives me internal server error but no error code ):
currently my workstation is a windows computer.
my log loooks like this: http://i.imgur.com/Xd3QAms.png
config.ru
require 'tilt/haml'
require 'sass/plugin/rack'
require '4c96748'
run Sinatra::Application
gemfile
source 'https://rubygems.org'
ruby '2.2.3'
gem 'sinatra', '1.1.0'
procfile
web: bundle exec rackup config.ru -p $PORT
4c96748.rb
require 'sinatra'
require 'tilt/haml'
get '/' do
haml :index
end
pleaase help me, what do i need to do?
try following in your 6c96748.rb
require 'rubygems'
require 'sinatra'
require 'haml'
get '/' do
haml :index
end
From your logfile:
LoadError - cannot load such file -- haml
There is no Haml installed on Heroku. Every dependency you need on Heroku needs to be in your Gemfile.
Add the following Line to Gemfile:
gem 'haml'
Don't forget to run bundle before commiting your changes and pushing to heroku again.
(As a sidenote, your Sinatra version is quite outdated. The current version is 1.4.6 (see https://rubygems.org/gems/sinatra))
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'm only need sinatra/base, but I don't know how to do it by using bundler. Because in the Gemfile I can't give it 'sinatra/base', but the gem name sinatra instead.
Any idea?
Use the following syntax in your Gemfile:
gem "sinatra", "X.Y.Z", :require => "sinatra/base"
You can then require it via bundler using the #require method:
Bundler.require :default
Hi so i stumbled upon a new way to require my ruby gems in my sinatra app using bundler and i was wondering if this is how i should do it:
My gem file looks like:
source 'https://rubygems.org'
gem 'sinatra'
gem 'thin'
gem 'haml'
My config.ru file looks like:
require 'rubygems'
require 'bundler'
Bundler.require
require './web'
run Sinatra::Application
My web.rb file looks like:
class MyApp
before do
cache_control :public, :max_age => 60
end
not_found do
haml :not_found
end
get '/' do
haml :index
end
end
Get rid of these lines from your config.ru file:
require 'rubygems'
require 'bundler'
Bundler.require
Just make sure you run
bundle install
from the terminal to install your gems before starting the application.
I'm wondering how one can use Bundler with Sinatra. The idea is to use the gems that Bundler downloads inside the .gems folder.
Inside your Sinatra app, you just have to require the bundler setup:
require "bundler/setup"
require "sinatra"
get "/" do
"Hello world!"
end
Alternatively, if you don't want to add the additional require "bundler/setup" at the top of your app, you can instead invoke sinatra via bundle exec (e.g. bundle exec ruby myapp.rb)
This assumes that you have a Gemfile in the root of your application. It might look like this:
source "http://rubygems.org"
gem "sinatra"
This also assumes that you've already installed bundler (gem install bundler) and that you ran bundle install to install all the gem dependencies.
I believe the best way is described here on EngineYard blog:
# This makes sure the bundled gems are in our $LOAD_PATH
require File.expand_path(File.join(File.dirname(__FILE__), 'vendor', 'gems', 'environment'))
# This actually requires the bundled gems
Bundler.require_env
class MyApp < Sinatra::Base
# stuff
end
As my original answer was quite old but there seems to be still attention to this topic here's the latest version of bundler/sinatra setup which will cover most of the use case:
A minimal config.ru
require './my_sinatra_app'
run MySinatraApp
An environment env.rb file that requires all the bundled gems (also supports loading the current environment's group):
require 'bundler/setup'
APP_ENV = ENV["RACK_ENV"] || "development"
Bundler.require :default, APP_ENV.to_sym
Then your app file (requiring the environment) with your sinatra app (Sinatra::Base):
require_relative 'env'
class MyApp < Sinatra::Base
get "/" do
"hello world"
end
end
Start your development server with rackup, and Sinatra will be loaded via Bundler, your app will be accessible from http://localhost:9292.
$ rackup
or bundle exec rackup if needed
Make sure you have a Gemfile like the following one and you run the bundle command before starting the app
source "https://rubygems.org"
gem "sinatra"
gem "puma" # a better rack server than the default webrick
+1 for the guide on the bundler website, but if you have a simple app and use Sinatra's dsl at the top level, then you need to do the following:
in your Gemfile (tell bundler not require sinatra):
gem 'sinatra', :require => false
and in the app's file (explicitly require sinatra):
require 'rubygems'
require 'bundler'
Bundler.require
require 'sinatra'
get '/' do
'hello world'
end
To use bundler with a Sinatra application, you only need to do two things. First, create a Gemfile.
gem 'sinatra'
Then, set up your config.ru file to load the bundle before it loads your Sinatra app.
require 'rubygems'
require 'bundler'
Bundler.require
require './my_sinatra_app'
run MySinatraApp
Start your development server with rackup, and Sinatra will be loaded via Bundler.
rackup
source bundler docs