# Gemfile:
source 'https://rubygems.org'
ruby '1.9.3'
gem 'sinatra'
gem 'figaro'
gem 'octokit'
# app.rb
require 'sinatra'
require 'json'
require 'cgi'
require 'octokit'
require 'figaro'
class Application < Sinatra::Base
get '/' do
'Hi'
end
end
# config.ru
require './app'
$stdout.sync = true
run Application
When push:
-----> Ruby/Rails app detected
However, if I remove figaro gem and repush it works fine.
You answered it yourself:
figaro depend on Rails (see the gemspec: https://github.com/laserlemon/figaro/blob/master/figaro.gemspec). Heroku detect rails application by looking if their Gemfile.lock contains the Railties gem, which is a dependency of rails.
So: yourapp -> figaro -> rails -> railties.
Hence the identification of your gem as a Rails App. Why are you using Figaro if not to help configure a Rails application anyway?
Related
I want to realize pagination in Sinatra with kaminari.
My Gemfile looks like this:
source "https://rubygems.org"
gem "sinatra"
gem "activerecord", :require => "active_record"
gem "mysql2"
gem "padrino-helpers"
gem "kaminari", :require => "kaminari/sinatra"
my Sinatra config.ru has a Bundler.require.
However, Passenger displays the following error: cannot load such file -- kaminari/sinatra
I don't know what's wrong. There is not much documentation about kaminari with Sinatra, and the only bit i found was: "You need padrino-helpers and require kaminari/sinatra". And that's what i did.
Sinatra (~> 1.4.0) depends on rack (1.5.2), while kaminari (~> 0.13.0) depends on rack (~> 1.2.1). And since kaminari only began experimental support for Sinatra since version 0.13.0, there appears to be an impasse.
I'm using spork to test a Sinatra application and with Ruby 1.9.2 the tests run in about 3.5 seconds but in Ruby 1.8.7 they average 1.2 seconds. I did try Ruby 1.9.3 and even JRuby but they had some errors with the gems I'm using. Is there a way to bring Ruby 1.9.2's rspec performance up to 1.8.7's level?
My Gemfile:
source :rubygems
gem 'sinatra', '1.3.1'
gem 'thin', '1.3.1'
gem 'haml', '3.1.4'
gem 'datamapper', '1.2.0'
gem 'dm-postgres-adapter', '1.2.0'
gem 'carrierwave', '0.5.8'
gem 'carrierwave-datamapper', '0.2.0'
group :test do
gem "dm-sqlite-adapter"
gem "spork"
gem "rspec"
gem "rack-test"
end
spec_helper.rb:
require 'rubygems'
require 'spork'
require 'sinatra'
require 'rack/test'
require 'rspec'
require File.join(File.dirname(__FILE__), '..', 'app.rb')
require File.join(File.dirname(__FILE__), '..', 'model/model.rb')
Spork.prefork do
set :environment, :test
set :files, "test_files"
end
Spork.each_run do
RSpec.configure do |config|
config.before(:each) { DataMapper.auto_migrate! }
config.after(:all) do
FileUtils.rm_rf(Dir["#{settings.root}/public/test_files"])
end
end
end
thanks!
There was a problem in the way ruby 1.9.2 require'd files during startup:
http://rhnh.net/2011/05/28/speeding-up-rails-startup-time
1.9.3 has a partial fix for this IIRC.
Not according to rspec's own test: https://gist.github.com/939865. It is supposed to be faster. It could be something slower in your stack.
hi, all
I build a sinatra app, the main files for bundling as the following,
environment.rb
require 'sinatra'
require 'sequel'
ENV['RACK_ENV'] = 'development'
configure :production do
#do something
end
configure :development, :test do
#do something
end
Gemfile
gem 'sinatra'
gem 'sequel'
gem 'pg', :group => :production
gem 'sqlite3', :group => [:development, :test]
So, how to let the bundle install based on the ENV['RACK_ENV'] in my environment.rb file.
When doing a bundler require you can specify which groups to be required.
For example:
require 'rubygems'
require 'bundler'
if ENV['RACK_ENV'] == 'development'
Bundler.require(:default, :development)
else
Bundler.require(:default)
require 'sinatra'
More info on the bundler site gemfile specifications found here.
Gemfile
source :rubygems
gem 'sinatra'
config.ru
require 'app'
run App
app.rb
require 'bundler/setup'
require 'sinatra'
class App < Sinatra::Base
get '/' do
'hello world'
end
end
rackup failes with
.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': no such file to load -- app (LoadError)
Works with ruby 1.8 . Why?
I think it's because 1.9.2 no longer includes '.' in the load path by default.
See the this question for more: Why does Ruby 1.9.2 remove "." from LOAD_PATH, and what's the alternative?
Some notes:
Gemfile, I use gem 'sinatra', :require => 'sinatra/base' to load a Modular Sinatra App.
Config.ru, usually I set Bundler on it, not in app.rb, leaving app.rb clean to my app.
require 'bundler/setup'
Bundler.require(:default)
I'm trying to get Bundler setup so I can deploy my Sinatra app to server with all the correct gems.
I've created my Gemfile
source :gemcutter
gem 'sinatra', '1.0'
gem "nokogiri", "1.4.2"
gem "rack", "1.1.0"
gem "dm-core", "1.0.0"
gem "dm-migrations", "1.0.0"
gem "dm-sqlite-adapter", "1.0.0"
gem "pony", "1.0"
Next I created a Config.ru
require 'rubygems'
require 'bundler'
Bundler.setup
require 'sinatra'
require 'dm-core'
require 'dm-migrations'
require 'dm-sqlite-adapter'
require 'open-uri'
require 'nokogiri'
require 'csv'
require 'pony'
require 'parsedate'
require 'digest/md5'
require 'MyApp'
run MyApp
So far so good, so next I ran bundle install and got 'Bundle Complete' so now all I need to do is just Rackup
Then I get:
config.ru:18: undefined local variable or method `MyApp' for #<Rack::Builder:0x1227350 #ins=[]> (NameError)
from /usr/local/lib/ruby/gems/1.8/gems/rack-1.1.0/lib/rack/builder.rb:46:in `instance_eval'
from /usr/local/lib/ruby/gems/1.8/gems/rack-1.1.0/lib/rack/builder.rb:46:in `initialize'
from config.ru:1:in `new'
from config.ru:1
Here's a simple MyApp.rb which will trigger the same error
get '/' do
erb :index
end
What's going wrong? :(
If you tell Rack to run MyApp, you need to define class MyApp first (which you're supposed to do inside MyApp.rb). Derive your class from Sinatra::Base to make it a Sinatra-Rack-App that can be run from config.ru:
require 'sinatra/base'
class MyApp < Sinatra::Base
get '/' do
erb :index
end
end
See also Sinatra's README about modular Sinatra apps (search for the paragraph named "Modular Apps" on http://github.com/sinatra/sinatra/)
Additionally you may have your my_app.rb as follows:
require 'rubygems'
require 'bundler'
Bundler.setup
require 'sinatra'
require 'dm-core'
require 'dm-migrations'
require 'dm-sqlite-adapter'
require 'open-uri'
require 'nokogiri'
require 'csv'
require 'pony'
require 'parsedate'
require 'digest/md5'
And your config.ru like this:
require './my_app'
run Rack::URLMap.new '/' => Sinatra::Application
Hope this helps.
Best Regards
ED
As an alternative to creating a modular app (wrapping your Sinatra methods in a class extending Sinatra::Base), you can use:
run Sinatra::Application
in the config.ru file in place of
run MyApp
This might be a better option if you want to keep the simple Sinatra code.
See the docs for more info.