I have just deployed my app to heroku, and after some problems, it seem to work.
But then i try to add a record to an sqlite3 database from the app, it’s not working, and isn’t redirecting me to ‘/’.
It’s a sinatra app, i have installed all the data mapper dependencies, and the logs doesn’t repost errors.
here is the code
require 'rubygems'
require 'sinatra'
require 'dm-core'
require 'dm-timestamps'
require 'dm-validations'
require 'dm-migrations'
DataMapper::setup(:default, "sqlite3://#{Dir.pwd}/rubrica.db")
class Contatto
include DataMapper::Resource
property :id, Serial
property :fname, Text
property :lname, Text
property :phone, Text
property :mail, Text
end
DataMapper.finalize.auto_upgrade!
get '/' do
@title = 'Tutti'
@Contatti = Contatto.all
erb :home
end
get '/add' do
@title = 'Aggiungi'
erb :aggiungi
end
post '/' do
c = Contatto.new
c.fname = params[:fname]
c.lname = params[:lname]
c.phone = params[:phone]
c.mail = params[:mail]
c.save
redirect '/'
end
and the link
here
The problem is that Heroku doesn’t use sqlite. If you specify sqlite as your database of choice, Heroku will do some black magic when it receives the push, and replace the sqlite3 gem with the postgres gem, and then run your application with a postgres database. So that explains why your
DataMapper::setup(:default, "sqlite3://#{Dir.pwd}/rubrica.db")call isn’t working.Read this Heroku doc for more information.
Upon some further reading of the Heroku docs, it appears that you need to change your call to Datamapper to be as such: