Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8610117
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:03:09+00:00 2026-06-12T04:03:09+00:00

I have a simple sinatra-activerecord app. Inside the file ./config/environments.rb I have the following

  • 0

I have a simple sinatra-activerecord app. Inside the file ./config/environments.rb I have the following configurations:

configure :development, :test do
  set :database, 'sqlite://database.db'
end

# These Heroku setup instructions can be at: https://devcenter.heroku.com/articles/rack
configure :production do
  # Database connection
  db = URI.parse(ENV['DATABASE_URL'] || 'postgres://localhost/mydb')

  ActiveRecord::Base.establish_connection(
    :adapter  => db.scheme == 'postgres' ? 'postgresql' : db.scheme,
    :host     => db.host,
    :username => db.user,
    :password => db.password,
    :database => db.path[1..-1],
    :encoding => 'utf8'
  )
end

When I push to Heroku, the DB setup works just fine. However, locally, it doesn’t. For example, if I do

$ rake db:migrate

I get the following fine output:

==  CreateHotels: migrating ===================================================
-- create_table(:hotels)
   -> 0.0015s
-- add_index(:hotels, :hotel_name)
   -> 0.0004s
==  CreateHotels: migrated (0.0021s) ==========================================

Now, if I start the server and use curl to make a call:

$ shotgun app.rb
$ curl -d "hotel_name=Sheraton" http://127.0.0.1:9393/hotels/

I get the following error:

ActiveRecord::StatementInvalid - Could not find table 'hotels':
    /Users/Sy/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.8/lib/active_record/connection_adapters/sqlite_adapter.rb:472:in `table_structure'
    /Users/Sy/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.8/lib/active_record/connection_adapters/sqlite_adapter.rb:346:in `columns'
    /Users/Sy/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.8/lib/active_record/connection_adapters/schema_cache.rb:12:in `block in initialize'
    /Users/Sy/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.8/lib/active_record/model_schema.rb:228:in `yield'
    /Users/Sy/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.8/lib/active_record/model_schema.rb:228:in `default'
    /Users/Sy/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.8/lib/active_record/model_schema.rb:228:in `columns'
    /Users/Sy/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.8/lib/active_record/model_schema.rb:243:in `column_defaults'
    /Users/Sy/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.8/lib/active_record/base.rb:482:in `initialize'
    /Users/Sy/Developer/Sinatra/stay-checkin-api/routes/hotels_routes.rb:8:in `new'
    /Users/Sy/Developer/Sinatra/stay-checkin-api/routes/hotels_routes.rb:8:in `block in <top (required)>'
    /Users/Sy/.rvm/gems/ruby-1.9.3-p125/gems/sinatra-1.3.3/lib/sinatra/base.rb:1265:in `call'
    /Users/Sy/.rvm/gems/ruby-1.9.3-p125/gems/sinatra-1.3.3/lib/sinatra/base.rb:1265:in `block in compile!'
    /Users/Sy/.rvm/gems/ruby-1.9.3-p125/gems/sinatra-1.3.3/lib/sinatra/base.rb:835:in `[]'
    /Users/Sy/.rvm/gems/ruby-1.9.3-p125/gems/sinatra-1.3.3/lib/sinatra/base.rb:835:in `block (3 levels) in route!'
    /Users/Sy/.rvm/gems/ruby-1.9.3-p125/gems/sinatra-1.3.3/lib/sinatra/base.rb:851:in `route_eval'
    /Users/Sy/.rvm/gems/ruby-1.9.3-p125/gems/sinatra-1.3.3/lib/sinatra/base.rb:835:in `block (2 levels) in route!'
    /Users/Sy/.rvm/gems/ruby-1.9.3-p125/gems/sinatra-1.3.3/lib/sinatra/base.rb:872:in `block in process_route'
    /Users/Sy/.rvm/gems/ruby-1.9.3-p125/gems/sinatra-1.3.3/lib/sinatra/base.rb:870:in `catch'
    /Users/Sy/.rvm/gems/ruby-1.9.3-p125/gems/sinatra-1.3.3/lib/sinatra/base.rb:870:in `process_route'
    /Users/Sy/.rvm/gems/ruby-1.9.3-p125/gems/sinatra-1.3.3/lib/sinatra/base.rb:834:in `block in route!'
    /Users/Sy/.rvm/gems/ruby-1.9.3-p125/gems/sinatra-1.3.3/lib/sinatra/base.rb:833:in `each'
    /Users/Sy/.rvm/gems/ruby-1.9.3-p125/gems/sinatra-1.3.3/lib/sinatra/base.rb:833:in `route!'
    /Users/Sy/.rvm/gems/ruby-1.9.3-p125/gems/sinatra-1.3.3/lib/sinatra/base.rb:936:in `dispatch!'
    /Users/Sy/.rvm/gems/ruby-1.9.3-p125/gems/sinatra-1.3.3/lib/sinatra/base.rb:769:in `block in call!'
    /Users/Sy/.rvm/gems/ruby-1.9.3-p125/gems/sinatra-1.3.3/lib/sinatra/base.rb:921:in `block in invoke'
    /Users/Sy/.rvm/gems/ruby-1.9.3-p125/gems/sinatra-1.3.3/lib/sinatra/base.rb:921:in `catch'
    /Users/Sy/.rvm/gems/ruby-1.9.3-p125/gems/sinatra-1.3.3/lib/sinatra/base.rb:921:in `invoke'
    /Users/Sy/.rvm/gems/ruby-1.9.3-p125/gems/sinatra-1.3.3/lib/sinatra/base.rb:769:in `call!'
    /Users/Sy/.rvm/gems/ruby-1.9.3-p125/gems/sinatra-1.3.3/lib/sinatra/base.rb:755:in `call'
    /Users/Sy/.rvm/gems/ruby-1.9.3-p125/gems/rack-protection-1.2.0/lib/rack/protection/xss_header.rb:22:in `call'
    /Users/Sy/.rvm/gems/ruby-1.9.3-p125/gems/rack-protection-1.2.0/lib/rack/protection/path_traversal.rb:16:in `call'
    /Users/Sy/.rvm/gems/ruby-1.9.3-p125/gems/rack-protection-1.2.0/lib/rack/protection/json_csrf.rb:17:in `call'
    /Users/Sy/.rvm/gems/ruby-1.9.3-p125/gems/rack-protection-1.2.0/lib/rack/protection/base.rb:47:in `call'
    /Users/Sy/.rvm/gems/ruby-1.9.3-p125/gems/rack-protection-1.2.0/lib/rack/protection/xss_header.rb:22:in `call'
    /Users/Sy/.rvm/gems/ruby-1.9.3-p125/gems/rack-1.4.1/lib/rack/nulllogger.rb:9:in `call'
    /Users/Sy/.rvm/gems/ruby-1.9.3-p125/gems/rack-1.4.1/lib/rack/head.rb:9:in `call'
    /Users/Sy/.rvm/gems/ruby-1.9.3-p125/gems/rack-1.4.1/lib/rack/methodoverride.rb:21:in `call'
    /Users/Sy/.rvm/gems/ruby-1.9.3-p125/gems/sinatra-1.3.3/lib/sinatra/showexceptions.rb:21:in `call'
    /Users/Sy/.rvm/gems/ruby-1.9.3-p125/gems/sinatra-1.3.3/lib/sinatra/base.rb:99:in `call'
    /Users/Sy/.rvm/gems/ruby-1.9.3-p125/gems/sinatra-1.3.3/lib/sinatra/base.rb:1389:in `block in call'
    /Users/Sy/.rvm/gems/ruby-1.9.3-p125/gems/sinatra-1.3.3/lib/sinatra/base.rb:1471:in `synchronize'
    /Users/Sy/.rvm/gems/ruby-1.9.3-p125/gems/sinatra-1.3.3/lib/sinatra/base.rb:1389:in `call'
    /Users/Sy/.rvm/gems/ruby-1.9.3-p125/gems/rack-1.4.1/lib/rack/lint.rb:48:in `_call'
    /Users/Sy/.rvm/gems/ruby-1.9.3-p125/gems/rack-1.4.1/lib/rack/lint.rb:36:in `call'
    /Users/Sy/.rvm/gems/ruby-1.9.3-p125/gems/rack-1.4.1/lib/rack/showexceptions.rb:24:in `call'
    /Users/Sy/.rvm/gems/ruby-1.9.3-p125/gems/rack-1.4.1/lib/rack/commonlogger.rb:20:in `call'
    /Users/Sy/.rvm/gems/ruby-1.9.3-p125/gems/sinatra-1.3.3/lib/sinatra/base.rb:136:in `call'
    /Users/Sy/.rvm/gems/ruby-1.9.3-p125/gems/shotgun-0.9/lib/shotgun/loader.rb:86:in `proceed_as_child'
    /Users/Sy/.rvm/gems/ruby-1.9.3-p125/gems/shotgun-0.9/lib/shotgun/loader.rb:31:in `call!'
    /Users/Sy/.rvm/gems/ruby-1.9.3-p125/gems/shotgun-0.9/lib/shotgun/loader.rb:18:in `call'
    /Users/Sy/.rvm/gems/ruby-1.9.3-p125/gems/shotgun-0.9/lib/shotgun/favicon.rb:12:in `call'
    /Users/Sy/.rvm/gems/ruby-1.9.3-p125/gems/rack-1.4.1/lib/rack/builder.rb:134:in `call'
    /Users/Sy/.rvm/gems/ruby-1.9.3-p125/gems/thin-1.4.1/lib/thin/connection.rb:80:in `block in pre_process'
    /Users/Sy/.rvm/gems/ruby-1.9.3-p125/gems/thin-1.4.1/lib/thin/connection.rb:78:in `catch'
    /Users/Sy/.rvm/gems/ruby-1.9.3-p125/gems/thin-1.4.1/lib/thin/connection.rb:78:in `pre_process'
    /Users/Sy/.rvm/gems/ruby-1.9.3-p125/gems/thin-1.4.1/lib/thin/connection.rb:53:in `process'
    /Users/Sy/.rvm/gems/ruby-1.9.3-p125/gems/thin-1.4.1/lib/thin/connection.rb:38:in `receive_data'
    /Users/Sy/.rvm/gems/ruby-1.9.3-p125/gems/eventmachine-1.0.0/lib/eventmachine.rb:187:in `run_machine'
    /Users/Sy/.rvm/gems/ruby-1.9.3-p125/gems/eventmachine-1.0.0/lib/eventmachine.rb:187:in `run'
    /Users/Sy/.rvm/gems/ruby-1.9.3-p125/gems/thin-1.4.1/lib/thin/backends/base.rb:63:in `start'
    /Users/Sy/.rvm/gems/ruby-1.9.3-p125/gems/thin-1.4.1/lib/thin/server.rb:159:in `start'
    /Users/Sy/.rvm/gems/ruby-1.9.3-p125/gems/rack-1.4.1/lib/rack/handler/thin.rb:13:in `run'
    /Users/Sy/.rvm/gems/ruby-1.9.3-p125/gems/shotgun-0.9/bin/shotgun:156:in `<top (required)>'
    /Users/Sy/.rvm/gems/ruby-1.9.3-p125/bin/shotgun:19:in `load'
    /Users/Sy/.rvm/gems/ruby-1.9.3-p125/bin/shotgun:19:in `<main>'

Any idea?

ps: here are my app.rb, config.rb, routes, and model file.

app.rb

require 'sinatra'
require 'sinatra/activerecord'
require 'uri'
require './config/environments'


require_relative 'models/init'
require_relative 'routes/init'

config.rb

require './app'
run Sinatra::Application

model: hotel.rb

class Hotel < ActiveRecord::Base
  validates :hotel_name, :presence => true    
end

routes: hotels_routes.rb

get '/hotels' do
  @hotels = Hotel.all
  if @hotels
      content_type :json
      @hotels.to_json
  end
end


post '/hotels/' do
  @hotel = Hotel.new
  @hotel.hotel_name = params[:hotel_name]
  if @hotel.save 
    content_type :json
    @hotel.to_json
  else
    content_type :json
    "Failed to create new hotel with name #{params[:hotel_name]}".to_json
  end
end

Gemfile

source :rubygems

gem 'heroku'
gem 'sinatra'
gem 'thin'
gem 'activerecord'
gem 'sinatra-activerecord'
gem 'json'

# Define which database gem to use depending on whether you are in local or production environment

group :development, :test do
  gem 'sqlite3'
end

group :production do
  gem 'pg' # this gem is required to use postgres on Heroku
end

Rakefile

require './app'
require 'sinatra/activerecord/rake'
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T04:03:11+00:00Added an answer on June 12, 2026 at 4:03 am

    The database set is wrong, try:

    set :database, 'sqlite:///database.db'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I tried to set up a config file for my sinatra app, and simple
I have a simple config.ru file for my Sinatra app. require 'sinatra' require 'app'
I have simple Sinatra app. web.rb: require 'sinatra' get '/' do Hello end Gemfile:*
I have a .Net XML webservice that I need a simple Sinatra app to
I have a simple Sinatra app that I will be hosting in tomcat as
I have a simple Sinatra app that I am playing with, and for some
I have a fairly simple app (just one index.html file and a css file
I have a Sinatra app utilizing Sequel and Postgres... it's a very simple module
I have a simple Sinatra app that you can use to record the beers
I have a simple Sinatra app that is configured using the modular style. When

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.