15.Apr.2017
> Creating RVM file
- cd projects\2017\ruby\doctor-is-in
- rvm use --create --rvmrc 2.4.1@doctor-is-in
> Create .GemFile
-subl GemFile
> Add item to GemFile
***
source 'http://rubygems.org'
ruby "2.4.1"
gem 'sinatra'
gem "activerecord"
gem "sinatra-activerecord"
#Tells your Mac to use sqlite locally during development
group :development do
gem 'sqlite3'
gem "tux"
end
#Tells heroku to use postgreSQL in production/live
group :production do
gem 'pg'
end
***
> Install bundler
- gem install bundler
> Run bundler
- bundle install
> Clone viz project
- git clone https://baliwme@bitbucket.org/baliwme/viz.git
> Create config.ru
***
# config.ru
require './myapp'
run Sinatra::Application
***
> Open my good old reference
- https://www.kylembrown.com/programming/sinatra-and-postgresql-perform-on-a-heroku-stage-tutorial
> Create database-config.rb
***
# database-config.rb
#Sets development database to sqlite
configure :development do
ActiveRecord::Base.establish_connection(
:adapter => 'sqlite3',
:database => 'db/DevDb.sqlite3',
:show_exceptions => true,
:connect_timeout => 30,
:pool => 10
)
end
#Sets production database to postgreSQL
configure :production do
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
***
> Create myapi.rb
***
# myapi.rb
require 'sinatra'
require 'sinatra/activerecord'
require './config/database-config'
class Doctor < ActiveRecord::Base
end
***
> Create Rakefile file
***
# Rakefile
#<a href="http://guides.rubyonrails.org/command_line.html#rake" target="_blank">Rake</a> is a build tool, written in Ruby, using Ruby as a build language. Rake is similar to make in scope and purpose. Rake a simple ruby build program with capabilities similar to make.
#ActiveRecord with be used for <a href="http://guides.rubyonrails.org/migrations.html" target="_blank">migrations</a>.
require './myapi'
require 'sinatra/activerecord/rake'
***
> Create Doctors table
- rake db:create_migration NAME=create_doctors
> Update db\migrate\20170415153551_create_doctors.rb
***
class CreateDoctors < ActiveRecord::Migration[5.0]
def self.up
create_table :doctors do |t|
t.string :first_name
t.string :middle_name
t.string :last_name
t.string :gender
t.string :email
t.text :bio
t.timestamps
end
end
def self.down
drop_table :doctors
end
end
***
> Start migration
- rake db:migrate
> Install gem shotgun
- gem install shotgun
- shotgun myapi.rb
14.Apr.2018
* Setup doctor-is-in ruby project
> Create project folder
- MkDir project\2017\doctor-is-in
> Initialize a git repo
- git init
> Clone heroku git repo
- heroku git:remote -a doctor-is-in
* Apply rvm
> Download latest stable ruby version 2.4.1
- rvm install 2.4.1
> Creating RVM file
- cd projects\2017\ruby\doctor-is-in
- rvm use --create --rvmrc 2.4.1@doctor-is-in
> Create .GemFile
-subl GemFile
> Add item to GemFile
***
source 'http://rubygems.org'
ruby "2.4.1"
gem 'sinatra'
gem "activerecord"
gem "sinatra-activerecord"
#Tells your Mac to use sqlite locally during development
group :development do
gem 'sqlite3'
gem "tux"
end
#Tells heroku to use postgreSQL in production/live
group :production do
gem 'pg'
end
***
> Install bundler
- gem install bundler
> Run bundler
- bundle install
> Clone viz project
- git clone https://baliwme@bitbucket.org/baliwme/viz.git
> Create config.ru
***
# config.ru
require './myapp'
run Sinatra::Application
***
> Open my good old reference
- https://www.kylembrown.com/programming/sinatra-and-postgresql-perform-on-a-heroku-stage-tutorial
> Create database-config.rb
***
# database-config.rb
#Sets development database to sqlite
configure :development do
ActiveRecord::Base.establish_connection(
:adapter => 'sqlite3',
:database => 'db/DevDb.sqlite3',
:show_exceptions => true,
:connect_timeout => 30,
:pool => 10
)
end
#Sets production database to postgreSQL
configure :production do
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
***
> Create myapi.rb
***
# myapi.rb
require 'sinatra'
require 'sinatra/activerecord'
require './config/database-config'
class Doctor < ActiveRecord::Base
end
***
> Create Rakefile file
***
# Rakefile
#<a href="http://guides.rubyonrails.org/command_line.html#rake" target="_blank">Rake</a> is a build tool, written in Ruby, using Ruby as a build language. Rake is similar to make in scope and purpose. Rake a simple ruby build program with capabilities similar to make.
#ActiveRecord with be used for <a href="http://guides.rubyonrails.org/migrations.html" target="_blank">migrations</a>.
require './myapi'
require 'sinatra/activerecord/rake'
***
> Create Doctors table
- rake db:create_migration NAME=create_doctors
> Update db\migrate\20170415153551_create_doctors.rb
***
class CreateDoctors < ActiveRecord::Migration[5.0]
def self.up
create_table :doctors do |t|
t.string :first_name
t.string :middle_name
t.string :last_name
t.string :gender
t.string :email
t.text :bio
t.timestamps
end
end
def self.down
drop_table :doctors
end
end
***
> Start migration
- rake db:migrate
> Install gem shotgun
- gem install shotgun
- shotgun myapi.rb
14.Apr.2018
* Setup doctor-is-in ruby project
> Create project folder
- MkDir project\2017\doctor-is-in
> Initialize a git repo
- git init
> Clone heroku git repo
- heroku git:remote -a doctor-is-in
* Apply rvm
> Download latest stable ruby version 2.4.1
- rvm install 2.4.1
Comments
Post a Comment