ruby - Sinatra app cannot find ActiveRecord tables -
i'm writing ruby app using rack, sinatra, active record, , sqlite3 (in-memory). setup in-memory db follows:
class mydatabase def self.init activerecord::base::establish_connection( :adapter => 'sqlite3', :database => ':memory:' ) activerecord::schema::define unless activerecord::base::connection.data_sources.include? 'my_table' create_table :my_table |table| table.column :age, :integer table.column :name, :string end end end end end
then in rack config file call:
mydatabase::init() run rack::urlmap.new( '/api/v1/some_route' => mycontroller.new )
however, if create connection database inside controller class , list of tables, it's empty. how can make application/sinatra controllers use tables create in mydatabase class?
the controllers declared as
mycontroller < sinatra::base
i've taken @ https://github.com/janko-m/sinatra-activerecord. against using i'd isolate database logic separate "data" layer (directory) in project (like mvc), hoping call setup logic rack config file @ startup.
Comments
Post a Comment