SlideShare a Scribd company logo
Ruby on Rails
#101 Preparing enviroment
What do you need
1. POSIX operating system (e.g. Mac OS X or Linux)
2. Knowledge about HTML, CSS/SASS, and JavaScript/
CoffeeScript
Fu*k off, Windows
Cloud9
Online IDE to the rescue
Getting started
1. A GitHub account
2. Log in Cloud9 with GitHub account
• Use Google Chrome
• Though I hate Google Chrome, it seems to be only full-
functional web browser after Cloud9 latest upgrade
3. Create a private workspace, based on custom
Going to learn
• Create a Ruby on Rails project
suspenders
Proudly released by thoughtbot
Install suspenders
1. Install Ruby 2.2.3 (latest version of Ruby)
2. Install necessary dependencies
3. Install suspenders
Install suspenders (Cont.)
# Install necessary dependencies for Capybara WebKit
$ sudo apt-get install qt5-default libqt5webkit5-dev
# Install minimal version which required by suspenders
$ rvm install 2.2.3
# Use it and set it to be default version
$ rvm use --default 2.2.3
# Install suspenders
$ gem install suspenders
Create a new Ruby on Rails project
1. Create a new project with suspenders
2. Replace PostgreSQL with SQLite3
• It is difficult for us to install PostgreSQL on Cloud9
3. Copy sample environment file and modify it
Create a new project with suspenders
$ suspenders demo --database sqlite3
• Replace demo with your project name
• The procedure shall fail due to we DO NOT have all
necessary dependencies
Replace postgresql with sqlite3
group :development do
...
gem "sqlite3"
...
end
1. Open Gemfile
2. Add sqlite3 to the development group
3. cd to project directory
4. Run bundle command
Environment variables?
• Sometimes we use third-party services, such as Amazon
Web Service, and we connect these services via application
ID and secret keys
• BUT we CANNOT place our secret keys in source code, it is
extremely DANGEROUS
• Environment variables to the rescue, which make sensitive
data isolated from source code
GitHub 10 AWS
6500
http://www.ithome.com.tw/news/98497
Sample environment file .sample.env
# http://ddollar.github.com/foreman/
ASSET_HOST=localhost:3000
APPLICATION_HOST=localhost:3000
RACK_ENV=development
SECRET_KEY_BASE=development_secret
EXECJS_RUNTIME=Node
Sample environment file .sample.env (Cont.)
• ASSET_HOST: Location for assets such as CSS files, JavaScript
files, and images. It may be different when using CDN
(Content Distribution Network)
• APPLICATION_HOST: Location of web application
• RAKE_ENV: Used by Ruby on Rails to isolate development,
testing, and production environment. "development" on
private machine, "production" on deployment platform
Sample environment file .sample.env (Cont.)
• SECRET_KEY_BASE: String for "salting" session key or
passwords, produced by rake secret
• EXECJS_RUNTIME: JavaScript runtime to execute Node.js
applications such as SASS (preprocessor for CSS) or
CoffeeScript (preprocessor for JavaScript)
Copy sample environment file
and modify it
# Copy the sample file
$ cp .sample.env .env
# Generate secret key base and copy it
$ rake secret
# Open .env and paste secret key base, and
# make SECRET_KEY_BASE=development_secret
# become SECRET_KEY_BASE=XXXXXX
Launch Ruby on Rails server
$ rails server -b $IP -p $PORT
• server: Run Ruby on Rails server
• -b: Specify IP address
• $IP: IP address, got from environment variables
• -p: Specify port
• $PORT: Application port, got from environment variables
DONE
If you see this, you got it
One more thing
Install simple_form
Forms made easy for Rails! It's tied to a simple DSL, with no
opinion on markup
rails generate simple_form:install --bootstrap
• generate generates configuration files related to
simple_form gem
• --bootstrap enables the integration with Twitter Bootstrap
End of Ruby on Rails #101
Ruby on Rails
#102 Create static pages
High voltage
Linkin park
high_voltage gem
1. Developed by thoughtbot
2. Easily include static pages in your Rails app.
Why bothered?
• Ruby on Rails is a web framework for dynamic content
• Though we can put HTML documents in public/ directory,
sometimes you need to embed some Ruby codes in HTML
documents
• high_voltage gem to the rescue
Getting started
1. Install high_voltage
2. Create a static page
3. Configure application dispatch
Install high_voltage
1. We don't need to install high_voltage gem. It has been
included in projects produced by suspenders
2. That's why we don't create the project from scratch
Create a static page
1. Create a new file in app/views/pages directory, called it
whatever you like, but remember it, I call it home.html.erb
2. Write any content inside the document, take the following
code as example
3. Save it
<h1>Hello, Ruby on Rails!</h1>
<p>Current time: <%= DateTime.now %></p>
Configure application dispatch
1. Open file config/routes.rb
2. Add route by adding the following code, id should be your
static file name
3. Save it
Rails.application.routes.draw do
root "high_voltage/pages#show", id: "home"
end
What does this line mean?
root "high_voltage/pages#show", id: "home"
1. root means we wants to set the mapping for route "/"
2. high_voltage/pages#show indicates the action we want to
map the route, it complies specific pattern
3. id: "home" is the parameter passed to the action
"specific pattern"
high_voltage/pages#show
[package_name]/[controller_name]#[action_name]
show is the action we want to map the route, and it belongs to
pages controller from package high_voltage
Restart web server
Ctrl+C then rails server -b $IP -p $PORT command
Troubleshoot
Sass::SyntaxError in HighVoltage::Pages#show
File to import not found or unreadable: refills/flashes.
1. https://github.com/thoughtbot/suspenders/issues/568
2. We can follow instructions and fix it, or we can just ignore it
3. Comment out @import "refills/flashes"; in app/
assets/stylesheets/application.scss
4. Restart web server
Result
Try to create another static pages
• Browse them via route pages/:page_name
• Replace :page_name with static page file name excluding
".html.erb"
End of Ruby on Rails #102
Homework
1. Create a new Ruby on Rails project from scratch
2. Create three web pages using high_voltage
3. Bouns: Create links to the second and third page on the first
page

More Related Content

What's hot

Vagrant for real (codemotion rome 2016)
Vagrant for real (codemotion rome 2016)Vagrant for real (codemotion rome 2016)
Vagrant for real (codemotion rome 2016)
Michele Orselli
 
Breaking Up With Your Data Center Presentation
Breaking Up With Your Data Center PresentationBreaking Up With Your Data Center Presentation
Breaking Up With Your Data Center Presentation
Telescope_Inc
 
Best Practices for creating WP REST API by Galkin Nikita
Best Practices for creating WP REST API by Galkin NikitaBest Practices for creating WP REST API by Galkin Nikita
Best Practices for creating WP REST API by Galkin Nikita
WordCamp Kyiv
 
Forget MAMP and WAMP, Use Virtual Box to Have a Real Ubuntu Server
Forget MAMP and WAMP, Use Virtual Box to Have a Real Ubuntu ServerForget MAMP and WAMP, Use Virtual Box to Have a Real Ubuntu Server
Forget MAMP and WAMP, Use Virtual Box to Have a Real Ubuntu Server
aaroncouch
 
Pluralsight Webinar: Simplify Your Project Builds with Docker
Pluralsight Webinar: Simplify Your Project Builds with DockerPluralsight Webinar: Simplify Your Project Builds with Docker
Pluralsight Webinar: Simplify Your Project Builds with Docker
Elton Stoneman
 
TechUG - Kubernetes 101 - May 2020
TechUG - Kubernetes 101 - May 2020TechUG - Kubernetes 101 - May 2020
TechUG - Kubernetes 101 - May 2020
Elton Stoneman
 
Controlling multiple VMs with the power of Python
Controlling multiple VMs with the power of PythonControlling multiple VMs with the power of Python
Controlling multiple VMs with the power of Python
Yurii Vasylenko
 
Ansible best practices
Ansible best practicesAnsible best practices
Ansible best practices
StephaneFlotat1
 
Getting Started with Ansible
Getting Started with AnsibleGetting Started with Ansible
Getting Started with Ansible
Ahmed AbouZaid
 
Ansible Introduction
Ansible Introduction Ansible Introduction
Ansible Introduction
Robert Reiz
 
Scale your Magento app with Elastic Beanstalk
Scale your Magento app with Elastic BeanstalkScale your Magento app with Elastic Beanstalk
Scale your Magento app with Elastic Beanstalk
Corley S.r.l.
 
Ansible: How to Get More Sleep and Require Less Coffee
Ansible: How to Get More Sleep and Require Less CoffeeAnsible: How to Get More Sleep and Require Less Coffee
Ansible: How to Get More Sleep and Require Less Coffee
Sarah Z
 
Your first sinatra app
Your first sinatra appYour first sinatra app
Your first sinatra appRubyc Slides
 
Exploring Docker Security
Exploring Docker SecurityExploring Docker Security
Exploring Docker Security
Patrick Kleindienst
 
Vagrant for real codemotion (moar tips! ;-))
Vagrant for real codemotion (moar tips! ;-))Vagrant for real codemotion (moar tips! ;-))
Vagrant for real codemotion (moar tips! ;-))
Michele Orselli
 
Ansible + WordPress
Ansible + WordPressAnsible + WordPress
Ansible + WordPress
Alan Lok
 
London Community Summit - Habitat 2016
London Community Summit - Habitat 2016London Community Summit - Habitat 2016
London Community Summit - Habitat 2016
Sarah Richards
 
Using Capifony for Symfony apps deployment (updated)
Using Capifony for Symfony apps deployment (updated)Using Capifony for Symfony apps deployment (updated)
Using Capifony for Symfony apps deployment (updated)
Žilvinas Kuusas
 
Infrastructure = Code
Infrastructure = CodeInfrastructure = Code
Infrastructure = Code
Georg Sorst
 

What's hot (20)

Vagrant for real (codemotion rome 2016)
Vagrant for real (codemotion rome 2016)Vagrant for real (codemotion rome 2016)
Vagrant for real (codemotion rome 2016)
 
Breaking Up With Your Data Center Presentation
Breaking Up With Your Data Center PresentationBreaking Up With Your Data Center Presentation
Breaking Up With Your Data Center Presentation
 
Best Practices for creating WP REST API by Galkin Nikita
Best Practices for creating WP REST API by Galkin NikitaBest Practices for creating WP REST API by Galkin Nikita
Best Practices for creating WP REST API by Galkin Nikita
 
Forget MAMP and WAMP, Use Virtual Box to Have a Real Ubuntu Server
Forget MAMP and WAMP, Use Virtual Box to Have a Real Ubuntu ServerForget MAMP and WAMP, Use Virtual Box to Have a Real Ubuntu Server
Forget MAMP and WAMP, Use Virtual Box to Have a Real Ubuntu Server
 
Pluralsight Webinar: Simplify Your Project Builds with Docker
Pluralsight Webinar: Simplify Your Project Builds with DockerPluralsight Webinar: Simplify Your Project Builds with Docker
Pluralsight Webinar: Simplify Your Project Builds with Docker
 
TechUG - Kubernetes 101 - May 2020
TechUG - Kubernetes 101 - May 2020TechUG - Kubernetes 101 - May 2020
TechUG - Kubernetes 101 - May 2020
 
Controlling multiple VMs with the power of Python
Controlling multiple VMs with the power of PythonControlling multiple VMs with the power of Python
Controlling multiple VMs with the power of Python
 
Ansible best practices
Ansible best practicesAnsible best practices
Ansible best practices
 
Getting Started with Ansible
Getting Started with AnsibleGetting Started with Ansible
Getting Started with Ansible
 
Ansible Introduction
Ansible Introduction Ansible Introduction
Ansible Introduction
 
Scale your Magento app with Elastic Beanstalk
Scale your Magento app with Elastic BeanstalkScale your Magento app with Elastic Beanstalk
Scale your Magento app with Elastic Beanstalk
 
Ansible: How to Get More Sleep and Require Less Coffee
Ansible: How to Get More Sleep and Require Less CoffeeAnsible: How to Get More Sleep and Require Less Coffee
Ansible: How to Get More Sleep and Require Less Coffee
 
Your first sinatra app
Your first sinatra appYour first sinatra app
Your first sinatra app
 
DockerCoreNet
DockerCoreNetDockerCoreNet
DockerCoreNet
 
Exploring Docker Security
Exploring Docker SecurityExploring Docker Security
Exploring Docker Security
 
Vagrant for real codemotion (moar tips! ;-))
Vagrant for real codemotion (moar tips! ;-))Vagrant for real codemotion (moar tips! ;-))
Vagrant for real codemotion (moar tips! ;-))
 
Ansible + WordPress
Ansible + WordPressAnsible + WordPress
Ansible + WordPress
 
London Community Summit - Habitat 2016
London Community Summit - Habitat 2016London Community Summit - Habitat 2016
London Community Summit - Habitat 2016
 
Using Capifony for Symfony apps deployment (updated)
Using Capifony for Symfony apps deployment (updated)Using Capifony for Symfony apps deployment (updated)
Using Capifony for Symfony apps deployment (updated)
 
Infrastructure = Code
Infrastructure = CodeInfrastructure = Code
Infrastructure = Code
 

Viewers also liked

Idea de negocio de revuelteria
Idea de negocio de revuelteriaIdea de negocio de revuelteria
Idea de negocio de revuelteria
juanpablo2312
 
Battle at the bluffs
Battle at the bluffsBattle at the bluffs
Battle at the bluffsTaylor Lynch
 
Fall '15 Catalog Feature
Fall '15 Catalog FeatureFall '15 Catalog Feature
Fall '15 Catalog FeatureKristen Albair
 
Hướng dẫn đăng ký thành viên và làm trắc nghiệm trên huongnghiep.icando.edu.vn
Hướng dẫn đăng ký thành viên và làm trắc nghiệm trên huongnghiep.icando.edu.vn Hướng dẫn đăng ký thành viên và làm trắc nghiệm trên huongnghiep.icando.edu.vn
Hướng dẫn đăng ký thành viên và làm trắc nghiệm trên huongnghiep.icando.edu.vn
Minh Le
 
Passeig i refresc
Passeig i refrescPasseig i refresc
Passeig i refrescclubsocial
 
Projeto Defensor - Solicitações
Projeto Defensor - Solicitações Projeto Defensor - Solicitações
Projeto Defensor - Solicitações Romero Albuquerque
 
24 Octombrie - Ziua Naţiunilor Unite/United Nations Day (ONU)
24 Octombrie - Ziua Naţiunilor Unite/United Nations Day (ONU)24 Octombrie - Ziua Naţiunilor Unite/United Nations Day (ONU)
24 Octombrie - Ziua Naţiunilor Unite/United Nations Day (ONU)
DIB ULIM
 
single maxillary denture/dental courses
single maxillary denture/dental coursessingle maxillary denture/dental courses
single maxillary denture/dental courses
Indian dental academy
 
Articulators and facebow/ dental implant courses
Articulators and facebow/ dental implant coursesArticulators and facebow/ dental implant courses
Articulators and facebow/ dental implant courses
Indian dental academy
 
ClassifIcation of complete denture patients/ hands on courses in dentistry
ClassifIcation of complete denture patients/ hands on courses in dentistryClassifIcation of complete denture patients/ hands on courses in dentistry
ClassifIcation of complete denture patients/ hands on courses in dentistry
Indian dental academy
 
Articulators1/prosthodontic courses
Articulators1/prosthodontic coursesArticulators1/prosthodontic courses
Articulators1/prosthodontic courses
Indian dental academy
 
Management of cross bite /certified fixed orthodontic courses by Indian dent...
Management of cross bite  /certified fixed orthodontic courses by Indian dent...Management of cross bite  /certified fixed orthodontic courses by Indian dent...
Management of cross bite /certified fixed orthodontic courses by Indian dent...
Indian dental academy
 

Viewers also liked (14)

Idea de negocio de revuelteria
Idea de negocio de revuelteriaIdea de negocio de revuelteria
Idea de negocio de revuelteria
 
Battle at the bluffs
Battle at the bluffsBattle at the bluffs
Battle at the bluffs
 
Fall '15 Catalog Feature
Fall '15 Catalog FeatureFall '15 Catalog Feature
Fall '15 Catalog Feature
 
Hướng dẫn đăng ký thành viên và làm trắc nghiệm trên huongnghiep.icando.edu.vn
Hướng dẫn đăng ký thành viên và làm trắc nghiệm trên huongnghiep.icando.edu.vn Hướng dẫn đăng ký thành viên và làm trắc nghiệm trên huongnghiep.icando.edu.vn
Hướng dẫn đăng ký thành viên và làm trắc nghiệm trên huongnghiep.icando.edu.vn
 
Passeig i refresc
Passeig i refrescPasseig i refresc
Passeig i refresc
 
sunny121
sunny121sunny121
sunny121
 
Optimization Model
Optimization ModelOptimization Model
Optimization Model
 
Projeto Defensor - Solicitações
Projeto Defensor - Solicitações Projeto Defensor - Solicitações
Projeto Defensor - Solicitações
 
24 Octombrie - Ziua Naţiunilor Unite/United Nations Day (ONU)
24 Octombrie - Ziua Naţiunilor Unite/United Nations Day (ONU)24 Octombrie - Ziua Naţiunilor Unite/United Nations Day (ONU)
24 Octombrie - Ziua Naţiunilor Unite/United Nations Day (ONU)
 
single maxillary denture/dental courses
single maxillary denture/dental coursessingle maxillary denture/dental courses
single maxillary denture/dental courses
 
Articulators and facebow/ dental implant courses
Articulators and facebow/ dental implant coursesArticulators and facebow/ dental implant courses
Articulators and facebow/ dental implant courses
 
ClassifIcation of complete denture patients/ hands on courses in dentistry
ClassifIcation of complete denture patients/ hands on courses in dentistryClassifIcation of complete denture patients/ hands on courses in dentistry
ClassifIcation of complete denture patients/ hands on courses in dentistry
 
Articulators1/prosthodontic courses
Articulators1/prosthodontic coursesArticulators1/prosthodontic courses
Articulators1/prosthodontic courses
 
Management of cross bite /certified fixed orthodontic courses by Indian dent...
Management of cross bite  /certified fixed orthodontic courses by Indian dent...Management of cross bite  /certified fixed orthodontic courses by Indian dent...
Management of cross bite /certified fixed orthodontic courses by Indian dent...
 

Similar to Ruby on Rails Kickstart 101 & 102

Docker for developers on mac and windows
Docker for developers on mac and windowsDocker for developers on mac and windows
Docker for developers on mac and windows
Docker, Inc.
 
Dev streams2
Dev streams2Dev streams2
Dev streams2
David Mc Donagh
 
From development environments to production deployments with Docker, Compose,...
From development environments to production deployments with Docker, Compose,...From development environments to production deployments with Docker, Compose,...
From development environments to production deployments with Docker, Compose,...
Jérôme Petazzoni
 
Women Who Code - RSpec JSON API Workshop
Women Who Code - RSpec JSON API WorkshopWomen Who Code - RSpec JSON API Workshop
Women Who Code - RSpec JSON API Workshop
Eddie Lau
 
Making a small QA system with Docker
Making a small QA system with DockerMaking a small QA system with Docker
Making a small QA system with Docker
Naoki AINOYA
 
Parse cloud code
Parse cloud codeParse cloud code
Parse cloud code維佋 唐
 
Introduction of webpack 4
Introduction of webpack 4Introduction of webpack 4
Introduction of webpack 4
Vijay Shukla
 
Cocoapods and Most common used library in Swift
Cocoapods and Most common used library in SwiftCocoapods and Most common used library in Swift
Cocoapods and Most common used library in Swift
Wan Muzaffar Wan Hashim
 
Just one-shade-of-openstack
Just one-shade-of-openstackJust one-shade-of-openstack
Just one-shade-of-openstack
Roberto Polli
 
[EXTENDED] Ceph, Docker, Heroku Slugs, CoreOS and Deis Overview
[EXTENDED] Ceph, Docker, Heroku Slugs, CoreOS and Deis Overview[EXTENDED] Ceph, Docker, Heroku Slugs, CoreOS and Deis Overview
[EXTENDED] Ceph, Docker, Heroku Slugs, CoreOS and Deis Overview
Leo Lorieri
 
MongoDB World 2018: Tutorial - Got Dibs? Building a Real-Time Bidding App wit...
MongoDB World 2018: Tutorial - Got Dibs? Building a Real-Time Bidding App wit...MongoDB World 2018: Tutorial - Got Dibs? Building a Real-Time Bidding App wit...
MongoDB World 2018: Tutorial - Got Dibs? Building a Real-Time Bidding App wit...
MongoDB
 
Docker module 1
Docker module 1Docker module 1
Docker module 1
Liang Bo
 
All girlhacknight intro to rails
All girlhacknight intro to railsAll girlhacknight intro to rails
All girlhacknight intro to rails
Nola Stowe
 
Continuous Integration with Docker on AWS
Continuous Integration with Docker on AWSContinuous Integration with Docker on AWS
Continuous Integration with Docker on AWS
Andrew Heifetz
 
Infrastructureascode slideshare-160331143725
Infrastructureascode slideshare-160331143725Infrastructureascode slideshare-160331143725
Infrastructureascode slideshare-160331143725
miguel dominguez
 
Infrastructureascode slideshare-160331143725
Infrastructureascode slideshare-160331143725Infrastructureascode slideshare-160331143725
Infrastructureascode slideshare-160331143725
MortazaJohari
 
Infrastructure as code: running microservices on AWS using Docker, Terraform,...
Infrastructure as code: running microservices on AWS using Docker, Terraform,...Infrastructure as code: running microservices on AWS using Docker, Terraform,...
Infrastructure as code: running microservices on AWS using Docker, Terraform,...
Yevgeniy Brikman
 
Supa fast Ruby + Rails
Supa fast Ruby + RailsSupa fast Ruby + Rails
Supa fast Ruby + Rails
Jean-Baptiste Feldis
 
Deploying applications to Windows Server 2016 and Windows Containers
Deploying applications to Windows Server 2016 and Windows ContainersDeploying applications to Windows Server 2016 and Windows Containers
Deploying applications to Windows Server 2016 and Windows Containers
Ben Hall
 

Similar to Ruby on Rails Kickstart 101 & 102 (20)

Docker for developers on mac and windows
Docker for developers on mac and windowsDocker for developers on mac and windows
Docker for developers on mac and windows
 
Dev streams2
Dev streams2Dev streams2
Dev streams2
 
From development environments to production deployments with Docker, Compose,...
From development environments to production deployments with Docker, Compose,...From development environments to production deployments with Docker, Compose,...
From development environments to production deployments with Docker, Compose,...
 
Women Who Code - RSpec JSON API Workshop
Women Who Code - RSpec JSON API WorkshopWomen Who Code - RSpec JSON API Workshop
Women Who Code - RSpec JSON API Workshop
 
Making a small QA system with Docker
Making a small QA system with DockerMaking a small QA system with Docker
Making a small QA system with Docker
 
Parse cloud code
Parse cloud codeParse cloud code
Parse cloud code
 
Introduction of webpack 4
Introduction of webpack 4Introduction of webpack 4
Introduction of webpack 4
 
Cocoapods and Most common used library in Swift
Cocoapods and Most common used library in SwiftCocoapods and Most common used library in Swift
Cocoapods and Most common used library in Swift
 
Just one-shade-of-openstack
Just one-shade-of-openstackJust one-shade-of-openstack
Just one-shade-of-openstack
 
[EXTENDED] Ceph, Docker, Heroku Slugs, CoreOS and Deis Overview
[EXTENDED] Ceph, Docker, Heroku Slugs, CoreOS and Deis Overview[EXTENDED] Ceph, Docker, Heroku Slugs, CoreOS and Deis Overview
[EXTENDED] Ceph, Docker, Heroku Slugs, CoreOS and Deis Overview
 
MongoDB World 2018: Tutorial - Got Dibs? Building a Real-Time Bidding App wit...
MongoDB World 2018: Tutorial - Got Dibs? Building a Real-Time Bidding App wit...MongoDB World 2018: Tutorial - Got Dibs? Building a Real-Time Bidding App wit...
MongoDB World 2018: Tutorial - Got Dibs? Building a Real-Time Bidding App wit...
 
Docker module 1
Docker module 1Docker module 1
Docker module 1
 
All girlhacknight intro to rails
All girlhacknight intro to railsAll girlhacknight intro to rails
All girlhacknight intro to rails
 
RoR guide_p1
RoR guide_p1RoR guide_p1
RoR guide_p1
 
Continuous Integration with Docker on AWS
Continuous Integration with Docker on AWSContinuous Integration with Docker on AWS
Continuous Integration with Docker on AWS
 
Infrastructureascode slideshare-160331143725
Infrastructureascode slideshare-160331143725Infrastructureascode slideshare-160331143725
Infrastructureascode slideshare-160331143725
 
Infrastructureascode slideshare-160331143725
Infrastructureascode slideshare-160331143725Infrastructureascode slideshare-160331143725
Infrastructureascode slideshare-160331143725
 
Infrastructure as code: running microservices on AWS using Docker, Terraform,...
Infrastructure as code: running microservices on AWS using Docker, Terraform,...Infrastructure as code: running microservices on AWS using Docker, Terraform,...
Infrastructure as code: running microservices on AWS using Docker, Terraform,...
 
Supa fast Ruby + Rails
Supa fast Ruby + RailsSupa fast Ruby + Rails
Supa fast Ruby + Rails
 
Deploying applications to Windows Server 2016 and Windows Containers
Deploying applications to Windows Server 2016 and Windows ContainersDeploying applications to Windows Server 2016 and Windows Containers
Deploying applications to Windows Server 2016 and Windows Containers
 

Recently uploaded

Acorn Recovery: Restore IT infra within minutes
Acorn Recovery: Restore IT infra within minutesAcorn Recovery: Restore IT infra within minutes
Acorn Recovery: Restore IT infra within minutes
IP ServerOne
 
Eureka, I found it! - Special Libraries Association 2021 Presentation
Eureka, I found it! - Special Libraries Association 2021 PresentationEureka, I found it! - Special Libraries Association 2021 Presentation
Eureka, I found it! - Special Libraries Association 2021 Presentation
Access Innovations, Inc.
 
Bonzo subscription_hjjjjjjjj5hhhhhhh_2024.pdf
Bonzo subscription_hjjjjjjjj5hhhhhhh_2024.pdfBonzo subscription_hjjjjjjjj5hhhhhhh_2024.pdf
Bonzo subscription_hjjjjjjjj5hhhhhhh_2024.pdf
khadija278284
 
Competition and Regulation in Professional Services – KLEINER – June 2024 OEC...
Competition and Regulation in Professional Services – KLEINER – June 2024 OEC...Competition and Regulation in Professional Services – KLEINER – June 2024 OEC...
Competition and Regulation in Professional Services – KLEINER – June 2024 OEC...
OECD Directorate for Financial and Enterprise Affairs
 
Bitcoin Lightning wallet and tic-tac-toe game XOXO
Bitcoin Lightning wallet and tic-tac-toe game XOXOBitcoin Lightning wallet and tic-tac-toe game XOXO
Bitcoin Lightning wallet and tic-tac-toe game XOXO
Matjaž Lipuš
 
Announcement of 18th IEEE International Conference on Software Testing, Verif...
Announcement of 18th IEEE International Conference on Software Testing, Verif...Announcement of 18th IEEE International Conference on Software Testing, Verif...
Announcement of 18th IEEE International Conference on Software Testing, Verif...
Sebastiano Panichella
 
Obesity causes and management and associated medical conditions
Obesity causes and management and associated medical conditionsObesity causes and management and associated medical conditions
Obesity causes and management and associated medical conditions
Faculty of Medicine And Health Sciences
 
Getting started with Amazon Bedrock Studio and Control Tower
Getting started with Amazon Bedrock Studio and Control TowerGetting started with Amazon Bedrock Studio and Control Tower
Getting started with Amazon Bedrock Studio and Control Tower
Vladimir Samoylov
 
somanykidsbutsofewfathers-140705000023-phpapp02.pptx
somanykidsbutsofewfathers-140705000023-phpapp02.pptxsomanykidsbutsofewfathers-140705000023-phpapp02.pptx
somanykidsbutsofewfathers-140705000023-phpapp02.pptx
Howard Spence
 
Sharpen existing tools or get a new toolbox? Contemporary cluster initiatives...
Sharpen existing tools or get a new toolbox? Contemporary cluster initiatives...Sharpen existing tools or get a new toolbox? Contemporary cluster initiatives...
Sharpen existing tools or get a new toolbox? Contemporary cluster initiatives...
Orkestra
 
Doctoral Symposium at the 17th IEEE International Conference on Software Test...
Doctoral Symposium at the 17th IEEE International Conference on Software Test...Doctoral Symposium at the 17th IEEE International Conference on Software Test...
Doctoral Symposium at the 17th IEEE International Conference on Software Test...
Sebastiano Panichella
 
0x01 - Newton's Third Law: Static vs. Dynamic Abusers
0x01 - Newton's Third Law:  Static vs. Dynamic Abusers0x01 - Newton's Third Law:  Static vs. Dynamic Abusers
0x01 - Newton's Third Law: Static vs. Dynamic Abusers
OWASP Beja
 
International Workshop on Artificial Intelligence in Software Testing
International Workshop on Artificial Intelligence in Software TestingInternational Workshop on Artificial Intelligence in Software Testing
International Workshop on Artificial Intelligence in Software Testing
Sebastiano Panichella
 

Recently uploaded (13)

Acorn Recovery: Restore IT infra within minutes
Acorn Recovery: Restore IT infra within minutesAcorn Recovery: Restore IT infra within minutes
Acorn Recovery: Restore IT infra within minutes
 
Eureka, I found it! - Special Libraries Association 2021 Presentation
Eureka, I found it! - Special Libraries Association 2021 PresentationEureka, I found it! - Special Libraries Association 2021 Presentation
Eureka, I found it! - Special Libraries Association 2021 Presentation
 
Bonzo subscription_hjjjjjjjj5hhhhhhh_2024.pdf
Bonzo subscription_hjjjjjjjj5hhhhhhh_2024.pdfBonzo subscription_hjjjjjjjj5hhhhhhh_2024.pdf
Bonzo subscription_hjjjjjjjj5hhhhhhh_2024.pdf
 
Competition and Regulation in Professional Services – KLEINER – June 2024 OEC...
Competition and Regulation in Professional Services – KLEINER – June 2024 OEC...Competition and Regulation in Professional Services – KLEINER – June 2024 OEC...
Competition and Regulation in Professional Services – KLEINER – June 2024 OEC...
 
Bitcoin Lightning wallet and tic-tac-toe game XOXO
Bitcoin Lightning wallet and tic-tac-toe game XOXOBitcoin Lightning wallet and tic-tac-toe game XOXO
Bitcoin Lightning wallet and tic-tac-toe game XOXO
 
Announcement of 18th IEEE International Conference on Software Testing, Verif...
Announcement of 18th IEEE International Conference on Software Testing, Verif...Announcement of 18th IEEE International Conference on Software Testing, Verif...
Announcement of 18th IEEE International Conference on Software Testing, Verif...
 
Obesity causes and management and associated medical conditions
Obesity causes and management and associated medical conditionsObesity causes and management and associated medical conditions
Obesity causes and management and associated medical conditions
 
Getting started with Amazon Bedrock Studio and Control Tower
Getting started with Amazon Bedrock Studio and Control TowerGetting started with Amazon Bedrock Studio and Control Tower
Getting started with Amazon Bedrock Studio and Control Tower
 
somanykidsbutsofewfathers-140705000023-phpapp02.pptx
somanykidsbutsofewfathers-140705000023-phpapp02.pptxsomanykidsbutsofewfathers-140705000023-phpapp02.pptx
somanykidsbutsofewfathers-140705000023-phpapp02.pptx
 
Sharpen existing tools or get a new toolbox? Contemporary cluster initiatives...
Sharpen existing tools or get a new toolbox? Contemporary cluster initiatives...Sharpen existing tools or get a new toolbox? Contemporary cluster initiatives...
Sharpen existing tools or get a new toolbox? Contemporary cluster initiatives...
 
Doctoral Symposium at the 17th IEEE International Conference on Software Test...
Doctoral Symposium at the 17th IEEE International Conference on Software Test...Doctoral Symposium at the 17th IEEE International Conference on Software Test...
Doctoral Symposium at the 17th IEEE International Conference on Software Test...
 
0x01 - Newton's Third Law: Static vs. Dynamic Abusers
0x01 - Newton's Third Law:  Static vs. Dynamic Abusers0x01 - Newton's Third Law:  Static vs. Dynamic Abusers
0x01 - Newton's Third Law: Static vs. Dynamic Abusers
 
International Workshop on Artificial Intelligence in Software Testing
International Workshop on Artificial Intelligence in Software TestingInternational Workshop on Artificial Intelligence in Software Testing
International Workshop on Artificial Intelligence in Software Testing
 

Ruby on Rails Kickstart 101 & 102

  • 1. Ruby on Rails #101 Preparing enviroment
  • 2. What do you need 1. POSIX operating system (e.g. Mac OS X or Linux) 2. Knowledge about HTML, CSS/SASS, and JavaScript/ CoffeeScript
  • 4. Cloud9 Online IDE to the rescue
  • 5. Getting started 1. A GitHub account 2. Log in Cloud9 with GitHub account • Use Google Chrome • Though I hate Google Chrome, it seems to be only full- functional web browser after Cloud9 latest upgrade 3. Create a private workspace, based on custom
  • 6. Going to learn • Create a Ruby on Rails project
  • 8. Install suspenders 1. Install Ruby 2.2.3 (latest version of Ruby) 2. Install necessary dependencies 3. Install suspenders
  • 9. Install suspenders (Cont.) # Install necessary dependencies for Capybara WebKit $ sudo apt-get install qt5-default libqt5webkit5-dev # Install minimal version which required by suspenders $ rvm install 2.2.3 # Use it and set it to be default version $ rvm use --default 2.2.3 # Install suspenders $ gem install suspenders
  • 10. Create a new Ruby on Rails project 1. Create a new project with suspenders 2. Replace PostgreSQL with SQLite3 • It is difficult for us to install PostgreSQL on Cloud9 3. Copy sample environment file and modify it
  • 11. Create a new project with suspenders $ suspenders demo --database sqlite3 • Replace demo with your project name • The procedure shall fail due to we DO NOT have all necessary dependencies
  • 12. Replace postgresql with sqlite3 group :development do ... gem "sqlite3" ... end 1. Open Gemfile 2. Add sqlite3 to the development group 3. cd to project directory 4. Run bundle command
  • 13. Environment variables? • Sometimes we use third-party services, such as Amazon Web Service, and we connect these services via application ID and secret keys • BUT we CANNOT place our secret keys in source code, it is extremely DANGEROUS • Environment variables to the rescue, which make sensitive data isolated from source code
  • 15. Sample environment file .sample.env # http://ddollar.github.com/foreman/ ASSET_HOST=localhost:3000 APPLICATION_HOST=localhost:3000 RACK_ENV=development SECRET_KEY_BASE=development_secret EXECJS_RUNTIME=Node
  • 16. Sample environment file .sample.env (Cont.) • ASSET_HOST: Location for assets such as CSS files, JavaScript files, and images. It may be different when using CDN (Content Distribution Network) • APPLICATION_HOST: Location of web application • RAKE_ENV: Used by Ruby on Rails to isolate development, testing, and production environment. "development" on private machine, "production" on deployment platform
  • 17. Sample environment file .sample.env (Cont.) • SECRET_KEY_BASE: String for "salting" session key or passwords, produced by rake secret • EXECJS_RUNTIME: JavaScript runtime to execute Node.js applications such as SASS (preprocessor for CSS) or CoffeeScript (preprocessor for JavaScript)
  • 18. Copy sample environment file and modify it # Copy the sample file $ cp .sample.env .env # Generate secret key base and copy it $ rake secret # Open .env and paste secret key base, and # make SECRET_KEY_BASE=development_secret # become SECRET_KEY_BASE=XXXXXX
  • 19. Launch Ruby on Rails server $ rails server -b $IP -p $PORT • server: Run Ruby on Rails server • -b: Specify IP address • $IP: IP address, got from environment variables • -p: Specify port • $PORT: Application port, got from environment variables
  • 20. DONE If you see this, you got it
  • 22. Install simple_form Forms made easy for Rails! It's tied to a simple DSL, with no opinion on markup rails generate simple_form:install --bootstrap • generate generates configuration files related to simple_form gem • --bootstrap enables the integration with Twitter Bootstrap
  • 23. End of Ruby on Rails #101
  • 24. Ruby on Rails #102 Create static pages
  • 26. high_voltage gem 1. Developed by thoughtbot 2. Easily include static pages in your Rails app.
  • 27. Why bothered? • Ruby on Rails is a web framework for dynamic content • Though we can put HTML documents in public/ directory, sometimes you need to embed some Ruby codes in HTML documents • high_voltage gem to the rescue
  • 28. Getting started 1. Install high_voltage 2. Create a static page 3. Configure application dispatch
  • 29. Install high_voltage 1. We don't need to install high_voltage gem. It has been included in projects produced by suspenders 2. That's why we don't create the project from scratch
  • 30. Create a static page 1. Create a new file in app/views/pages directory, called it whatever you like, but remember it, I call it home.html.erb 2. Write any content inside the document, take the following code as example 3. Save it <h1>Hello, Ruby on Rails!</h1> <p>Current time: <%= DateTime.now %></p>
  • 31. Configure application dispatch 1. Open file config/routes.rb 2. Add route by adding the following code, id should be your static file name 3. Save it Rails.application.routes.draw do root "high_voltage/pages#show", id: "home" end
  • 32. What does this line mean? root "high_voltage/pages#show", id: "home" 1. root means we wants to set the mapping for route "/" 2. high_voltage/pages#show indicates the action we want to map the route, it complies specific pattern 3. id: "home" is the parameter passed to the action
  • 33. "specific pattern" high_voltage/pages#show [package_name]/[controller_name]#[action_name] show is the action we want to map the route, and it belongs to pages controller from package high_voltage
  • 34. Restart web server Ctrl+C then rails server -b $IP -p $PORT command
  • 35. Troubleshoot Sass::SyntaxError in HighVoltage::Pages#show File to import not found or unreadable: refills/flashes. 1. https://github.com/thoughtbot/suspenders/issues/568 2. We can follow instructions and fix it, or we can just ignore it 3. Comment out @import "refills/flashes"; in app/ assets/stylesheets/application.scss 4. Restart web server
  • 37. Try to create another static pages • Browse them via route pages/:page_name • Replace :page_name with static page file name excluding ".html.erb"
  • 38. End of Ruby on Rails #102
  • 39. Homework 1. Create a new Ruby on Rails project from scratch 2. Create three web pages using high_voltage 3. Bouns: Create links to the second and third page on the first page