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))
Related
having trouble pushing my sinatra app to heroku based on the current setup. I have looked through all of the docs on heroku to figure this out but alas, i'm without resolution and continue to get the following error. No default language could be detected for this app.
app
--.git
-- public
-- views
- app.rb
- config.ru
- gemfile
- Gemfile.lock
- Procfile
- foo.csv
Procfile
web: bundle exec ruby app.rb -p $PORT
config.ru
require './app'
run Sinatra::Application
Gemfile
source 'https://rubygems.org'
ruby "2.4.0"
gem 'sinatra'
app.rb
require 'rubygems'
require 'sinatra'
require 'csv'
Tilt.register Tilt::ERBTemplate, 'html.erb'
set :public_folder, 'public'
get "/" do
erb :index
end
Update
Still not quite sure what the issue was here. I ended up grabbing the following sinatra/heroku shell from github, and replaced it with the assets from my app. Once I ran a bundle and pushed to heroku everything ended up working. I'm sure the issue is structurally nuanced and can be pulled from a deeper look at the working setup, for now - i'm just happy it's working.
https://github.com/runemadsen/Sinatra-Heroku-Template
I'm looking to run migrations for a Sinatra app called "sinatra_active_record_start" but can't get my settings right.
When I run bundle exec rake -T I get:
LoadError: cannot load such file -- sinatra_active_record_start
/Users/jasonnappy/ga_wdi/exisiting_resources/wdi_london/resources/materials/local/06-server-applications/ruby/sinatra/active-record/sinatra_active_record_start/Rakefile:1:in `require'
Same as when I run:
bundle exec rake db:create_migration first_migration
My Gemfile is:
source "https://rubygems.org"
gem "sinatra"
gem "activerecord"
gem "sinatra-activerecord"
gem "rake"
gem "thin"
My Rakefile is:
require "sinatra_active_record_start"
require "sinatra/activerecord/rake"
namespace :db do
desc "Migrate the database"
task(:migrate => :environment) do
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Migration.verbose = true
ActiveRecord::Migrator.migrate("db/migrate")
end
end
The top of app.rb is:
require "bundler/setup"
require "sinatra"
require "activerecord"
require "sinatra/activerecord"
I know there are some redundancies, but at this point, I'm just trying to plug in and make something work that I found on the internet.
First, it doesn't look like you are requiring an adapter for your database. Adding one, like
gem "sqlite3"
to your Gemfile, should fix that.
Second, sinatra/activerecord creates migrations in a directory called "db/migrate" by default. That's where your migrations should live, not the root directory.
Move your migration there and remove
require "sinatra_active_record_start"
from your Rakefile. That's the code that is causing the immediate error. You shouldn't need to require each migration in the Rakefile.
Following these steps should make your migrations run, although you should rename the file to follow ActiveRecord convention. Run
rake db:create_migration NAME='sinatra_active_record_start'
to create a new one with a timestamp.
"Sinatra Active Record Starter Kit" is an example repo to help you get started.
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
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'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