Ruby on Rails with PosgreSQL : Basic tutorial
Installation Steps
- Install Ubuntu and upgrade
- Install Apache2
- Install Rails
- Install Ruby
- Install Passenger
More Info: https://nathanhoad.net/how-to-ruby-on-rails-ubuntu-apache-with-passenger
Command Guides
* To install Apache 2 development headers:
sudo apt-get install apache2-dev
* To install Ruby development headers:
sudo apt-get install ruby-dev
* To install Passenger
gem install passenger
passenger-install-apache2-module
* To install Apache Portable Runtime (APR) development headers:
sudo apt-get install libapr1-dev
* To install Apache Portable Runtime Utility (APU) development headers:
sudo apt-get install libaprutil1-dev
* To install Curl development headers with SSL support:
sudo apt-get install libcurl4-openssl-dev
(or libcurl4-gnutls-dev)
------------ Set config passenger -----------
LoadModule passenger_module /home/web05/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/passenger-5.3.4/buildout/apache2/mod_passenger.so
PassengerRoot /home/web05/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/passenger-5.3.4
PassengerDefaultRuby /home/web05/.rbenv/versions/2.5.1/bin/ruby
sudo vim /etc/apache2/apache2.conf
service apache2 restart
-----------------------------------------------------More about apache passenger:
https://www.phusionpassenger.com/library/install/apache/
https://www.phusionpassenger.com/library/admin/apache/troubleshooting/
Start A Project
//Create project name "studentdb" with a database
rails new students -d postgresql
cd studentdb
bundle install
Gemfile
bundle install
rake db:create
//List database
psql -l
//Install a JavaScript execution environment: LAB02-03
gem 'mini_racer', platforms: :ruby
gem 'devise'
gem 'bcrypt'
//Create table "project"
rails generate scaffold project name:string url:string
//See in file -> db/migrate/*
rake db:migrate
rails server
//Edit controller "projects"
vim app/controllers/projects controller.rb
//Go to -> http://localhost:3000/projects.xml
//Generate model "student"
rails generate model student studentid:string name:string project:references
vim app/models/student.rb
rake db:migrate
//Set project has_many :students
//See https://guides.rubyonrails.org/routing.html
vim config/routes.rb
//Generate controller "students"
rails generate controller students
//This will create the controller class app/controllers/students/controller.rb and the view directory app/views/students/
//Edit controller "students"
vim app/controllers/students controller.rb
//Edit view "project"
vim app/views/projects/show.html.erb
//Set site route to "projects#index"
vim config/routes.rb -> root "projects#index"
More info:
Don’t Repeat Yourself, or DRY http://everydayrails.com/2010/09/27/rails-refactoring-tools.html
Comments