Heroku Deployment of Rails App - estermer/ericstermer.com GitHub Wiki
-
git init
,git add -A
,git commit -m "First Commit"
$ heroku create
$ git push heroku master
$ heroku run rails db:migrate
-
$ heroku run console
patient = Patient.create(name: "Schmitty", insurance_co: "Anthem", gender: "M", new_patient: true)
doctor = Doctor.create(name: "Dr. Robert", specialty: "feet", insurance: true, gender: "M") appointment_one = Appointment.create(location: "Grady General", day: "Monday", reason: "smelly feet", doctor_id: 1, patient_id: 1)
doctor.patients.create(name: "Diesel", insurance_co: "Blue Cross", gender: "M", new_patient: false) patient.doctors.create(name: "Dr. Foster", specialty: "Veterinary", gender: "M") appointment_two = Appointment.create(location: "Inman Park", day: "Friday", reason: "shots", doctor_id: doctor.id, patient_id: patient.id)
#### We could also add some data to our `db/seeds.rb` using the Faker gem
1. Add to `db/seeds.rb`
```rb
Appointment.destroy_all
Patient.destroy_all
Doctor.destroy_all
10.times do
Patient.create(name: Faker::Name.name, insurance_co: Faker::Beer.malts, gender: "F", new_patient: Faker::Boolean.boolean)
Doctor.create(name: Faker::Name.name, specialty: Faker::Hipster.word, gender: "F", insurance: Faker::Boolean.boolean)
end
10.times do
Appointment.create(location: Faker::University.name, day: Faker::Date.forward(23), reason: Faker::Hipster.sentence(6), patient_id: Faker::Number.between(1, 10), doctor_id: Faker::Number.between(1, 10))
end
-
rails db:reset
Note: This will drop the local databases, recreate, migrate and seed
-
Make sure to do another
git add -A
andgit commit
to push the file up to Heroku so we can seed our production database. -
$ heroku pg:reset DATABASE
-
$ heroku run rails db:migrate
-
Then run
$ heroku run rails db:seed
-
<NAME_ OF_YOUR_HEROKU_APP_HERE>/api/patients
-
<NAME_ OF_YOUR_HEROKU_APP_HERE>/api/doctors
-
Try to add a new Patient.
-
Try to add an Appointment.
-
mkdir rails5-api-angular-frontend_2
&&cd
into it -
npm init -y
-
touch server.js
var express = require('express'); var app = express(); var path = require('path'); app.use(express.static(path.join(__dirname,'public'))); app.get('/', function(req, res){ res.render('index'); }); app.listen(4000, function(){ console.log("app listening on port 4000"); });
-
npm install --save express path
-
mkdir public
-
mkdir public/js
-
touch public/js/app.js
(function(){ angular.module('Rails5', []); })()
1. `touch public/js/rails5Controller.js`
```js
(function(){
angular.module('Rails5')
.controller('rails5Controller', rails5Controller);
function rails5Controller($http){
var self = this;
var server = "<YOUR_HEROKU_API_LINK_HERE>"
// For example, var server = 'https://enigmatic-garden-65625.herokuapp.com/api/'
$http.get(`${server}/doctors`)
.then(function(response) {
self.doctors = response.data;
console.log(self.doctors[0].name);
});
}
})()
-
touch public/index.html
<!DOCTYPE html> <html ng-app="Rails5"> <head> <meta charset="utf-8"> <title>Rails 5 API App</title> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script> <script src='js/app.js'></script> <script src='js/rails5Controller.js'></script> </head> <body ng-controller="rails5Controller as rails"> <h1>Rails 5</h1> <ul ng-repeat="appointment in rails.appointments"> <li>{{appointment.location}}</li> </ul> {{1 + 1}} </body> </html>
-
touch Procfile
-web: node server.js