SlideShare a Scribd company logo
SO FOLKSSO FOLKS
WANT TOWANT TO
YOUYOU
Ruby on Rails
SO, RUBY IS...SO, RUBY IS...
A dynamic programming language
Focused on simplicity and
productivity
Has an elegant syntax
Natural to read and easy to write
THE IDEALS OF IT’S CREATORTHE IDEALS OF IT’S CREATOR
“ Ruby is simple in appearance, but is very
complex inside, just like our human body
Yukihiro “Matz” Matsumoto
Ruby is a language of careful balance
Blended of Perl, Smalltalk, Eiffel, Ada, and Lisp
Language that balanced functional
programming with imperative programming
RUBY’S GROWTHRUBY’S GROWTH
Released in 1995
Achieved mass acceptance in 2006
Ranked among the top 10 on most of the
indices that measure the growth and
popularity of programming languages
worldwide
DEMAND OF RUBYDEMAND OF RUBY
graph by TIOB
E
EVERYTHING IS AN OBJECTEVERYTHING IS AN OBJECT
“ I wanted a scripting language that was more powerful
than Perl, and more object-oriented than Python
Yukihiro “Matz” Matsumoto
In Ruby, everything is an object
Object-oriented programming calls properties by the
name instance variables and actions are known as methods
Ruby follows the influence of the
language by giving methods and instance
variables to all of its types
Smalltalk
5.times { print "We *love* Ruby -- it's outrageous!n" }
RUBY’S FLEXIBILITYRUBY’S FLEXIBILITY
Ruby is seen as a flexible language
It allows its users to freely alter its parts
Essential parts can be removed/redefined, at will
Existing parts can be added upon
Ruby tries not to restrict the coder
class Numeric
def plus(x)
self.+(x)
end
end
y = 5.plus 6
Use the readable word plus to
Ruby’s builtin Numeric class
BUILT WITH RUBYBUILT WITH RUBY AND RAILSAND RAILS
AND NOWAND NOW
WHAT IS RAILS ?WHAT IS RAILS ?
A web application framework written in Ruby
Uses model–view–controller (MVC)
Provides structures for database/web service/pages
JSON or XML for data transfer
Rails emphasizes the use of:
convention over configuration (CoC)
active record pattern
don't repeat yourself (DRY)
A WORD ABOUT ARA WORD ABOUT AR (Active Record)
active record pattern is architectural pattern
This is approach to accessing data in a database
Interface of this pattern would include:
Insert Update Delete
+ properties that correspond to columns in
underlying database table
/ /
SO...SO...
In AR database table or view is wrapped into a class
Object instance is tied to a single row in the table
Object created = new row is added to the table
Object updated = row is also updated
Object implements accessor methods for each
column in the table
Object removed = row removed too
C# FELLAS MAY CHECKOUT ACTIVEC# FELLAS MAY CHECKOUT ACTIVE
RECORD IMPLEMENTATION BYRECORD IMPLEMENTATION BY CASTLECASTLE
PROJECTPROJECT::
OKAYOKAY
LETS GET IT INSTALLEDLETS GET IT INSTALLED
FOR LINUXFOR LINUX
Or via Ruby Version Manager (RVM)
$ sudo apt-get install ruby-full
$ curl -sSL https://get.rvm.io | bash -s stable
$ rvm install ruby
$ rvm use ruby --default
$ rvm rubygems current
Simply
EASY AS HELL
Finally
$ gem install rails
FOR WINDOWSFOR WINDOWS
For God's (and your nerves) sake:
Go to:
Click most inconspicuous button
1.
2.
Like this one
AND JUST RUN GODDAMN INSTALLATIONAND JUST RUN GODDAMN INSTALLATION
FINALLYFINALLY
Check all things are installed successfully
$ ruby -v
ruby 2.0.0p (2015-04-13)
IF SO - WE'RE GOOD TO GO
$ gem -v
2.4.8
$ rails -v
Rails 4.2.3
$ sqlite3 --version
3.8.11.1 2015-07-15....
LETS SCAFFOLD !LETS SCAFFOLD !
Create new Rails project in folder `blog`
$ rails new blog
Install all dependency gems
$ bundle install
$ cd blog
Enter project folder
Run Rails server
$ rails server $ rails sor
PROFITPROFIT not yet...
http://localhost:3000
WELCOME ABOARDWELCOME ABOARD
Folder Description
/app controllers, models, views and assets for application
/config Application's routes, database, etc.
/db Contains database schema and migrations
/public Static files and compiled assets
/test Unit tests and fixtures
/tmp Cache, pid, and session files
/vendor Place for all third-party code
LETS CLARIFY
DOES RAILS USE
WHAT STACK
eRuby
Instead of plain JS
To make CSS debugging even more fun
Templating system similar to ASP, JSP and PHP
Quite unexpected, isn't it ?
&
To compile into plain JS
COFFEESCRIPTCOFFEESCRIPT
If you ever wondered how it work
square = (x) -> x * x
cube = (x) -> square(x) * x
alert square 2
var cube, square;
square = function(x) {
return x * x;
};
cube = function(x) {
return square(x) * x;
};
alert(square(2));
CoffeeScript JavaScript
RAILS CLIRAILS CLI
There are a few commands of everyday usage.
In the order of how much you'll use them are:
rails console
rails server
rake
rails generate
rails dbconsole
rails new app_name
All commands can run with -h or --help to list more information.
GENERATEGENERATE
$ bin/rails generate controller Greetings hello
create app/controllers/greetings_controller.rb
route get "greetings/hello"
invoke erb
create app/views/greetings
create app/views/greetings/hello.html.erb
invoke test_unit
create test/controllers/greetings_controller_test.rb
invoke helper
create app/helpers/greetings_helper.rb
invoke assets
invoke coffee
create app/assets/javascripts/greetings.js.coffee
invoke scss
create app/assets/stylesheets/greetings.css.scss
WE GET THISWE GET THIS
class GreetingsController < ApplicationController
def hello
@message = "Hello, how are you today?"
end
end
app/controllers/greetings_controller.rb
<h1>A Greeting for You!</h1>
<p><%= @message %></p>
app/views/greetings/hello.html.erb
RAILS `SCAFFOLD`RAILS `SCAFFOLD`
A scaffold in Rails is a full set of:
AS A MORE SUITABLE TOOL FOR GENERATING STUFF
model
database migration for the model
controller
FOR EXAMPLEFOR EXAMPLE
$ bin/rails generate scaffold HighScore game:string score:integer
invoke active_record
create db/migrate/20130717151933_create_high_scores.rb
create app/models/high_score.rb
invoke test_unit
create test/models/high_score_test.rb
create test/fixtures/high_scores.yml
invoke resource_route
route resources :high_scores
invoke scaffold_controller
create app/controllers/high_scores_controller.rb
invoke erb
create app/views/high_scores
create app/views/high_scores/index.html.erb
create app/views/high_scores/edit.html.erb
create app/views/high_scores/show.html.erb
create app/views/high_scores/new.html.erb
create app/views/high_scores/_form.html.erb
...
...
invoke test_unit
create test/controllers/high_scores_controller_test.rb
invoke helper
create app/helpers/high_scores_helper.rb
invoke jbuilder
create app/views/high_scores/index.json.jbuilder
create app/views/high_scores/show.json.jbuilder
invoke assets
invoke coffee
create app/assets/javascripts/high_scores.js.coffee
invoke scss
create app/assets/stylesheets/high_scores.css.scss
invoke scss
identical app/assets/stylesheets/scaffolds.css.scss
AND RAKEAND RAKE
Rake is a Make-like program implemented in
Ruby.
Except tasks and dependencies are
specified in standard Ruby syntax.
WE USE RAILS FOR:WE USE RAILS FOR:
Running db migrations
Seeding database with preset data
Getting list of all routes
Running test
LETS FIND OUT WHAT WE CAN RAKELETS FIND OUT WHAT WE CAN RAKE
Simply typing:
$ bin/rake --tasks
We get:
rake about # List versions of all Rails frameworks and the environment
rake assets:clean # Remove old compiled assets
rake assets:clobber # Remove compiled assets
rake assets:precompile # Compile all the assets named in config.assets.precompile
rake db:create # Create the database from config/database.yml for the current Rails.en
...
rake log:clear # Truncates all *.log files in log/ to zero bytes
rake middleware # Prints out your Rack middleware stack
...
rake tmp:clear # Clear session, cache, and socket files from tmp/
rake tmp:create # Creates tmp directories for sessions, cache, sockets, and pids
AND THATS ALLAND THATS ALL
CHECKOUT `HELLO WORLD` REPOCHECKOUT `HELLO WORLD` REPO
FURTHER LEARNINGFURTHER LEARNING
Ruby
Rails
GREAT SCREENCASTS:GREAT SCREENCASTS:
https://mackenziechild.me/12-in-12/
THANK YOU !THANK YOU !
QUESTIONS ?QUESTIONS ?

More Related Content

What's hot (17)

PPT
Ruby on Rails
thinkahead.net
 
PPT
Ruby on rails
TAInteractive
 
PDF
Ruby On Rails Basics
Amit Solanki
 
PDF
Flickr Architecture Presentation
eraz
 
PPTX
Getting started with laravel
Advance Idea Infotech
 
PPTX
Laravel Eloquent ORM
Ba Thanh Huynh
 
PPT
Jasig rubyon rails
_zaMmer_
 
PDF
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory Course
peter_marklund
 
PDF
RoR (Ruby on Rails)
scandiweb
 
PPTX
Chaos Testing with F# and Azure by Rachel Reese at Codemotion Dubai
Codemotion Dubai
 
PDF
API Platform and Symfony: a Framework for API-driven Projects
Les-Tilleuls.coop
 
PDF
Making the Most of Modern PHP in Drupal 7
Ryan Szrama
 
PPTX
Rails Engine Patterns
Andy Maleh
 
PDF
FP Concepts
Diego Pacheco
 
PDF
Laravel Restful API and AngularJS
Blake Newman
 
PPTX
Introduction to Ruby on Rails
Amit Patel
 
PPTX
Rails Engine | Modular application
mirrec
 
Ruby on Rails
thinkahead.net
 
Ruby on rails
TAInteractive
 
Ruby On Rails Basics
Amit Solanki
 
Flickr Architecture Presentation
eraz
 
Getting started with laravel
Advance Idea Infotech
 
Laravel Eloquent ORM
Ba Thanh Huynh
 
Jasig rubyon rails
_zaMmer_
 
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory Course
peter_marklund
 
RoR (Ruby on Rails)
scandiweb
 
Chaos Testing with F# and Azure by Rachel Reese at Codemotion Dubai
Codemotion Dubai
 
API Platform and Symfony: a Framework for API-driven Projects
Les-Tilleuls.coop
 
Making the Most of Modern PHP in Drupal 7
Ryan Szrama
 
Rails Engine Patterns
Andy Maleh
 
FP Concepts
Diego Pacheco
 
Laravel Restful API and AngularJS
Blake Newman
 
Introduction to Ruby on Rails
Amit Patel
 
Rails Engine | Modular application
mirrec
 

Viewers also liked (9)

PPTX
Frontend Workflow
DelphiCon
 
PPTX
IoC and Dependency Injection
DelphiCon
 
PPTX
No SQL
DelphiCon
 
PPTX
Effective email communications with a customer
DelphiCon
 
PPTX
Сборка Front-end’a
DelphiCon
 
PPTX
React.js
DelphiCon
 
PPTX
Garbage collector
DelphiCon
 
PPTX
SOLID
DelphiCon
 
PPTX
RESTful API and ASP.NET
DelphiCon
 
Frontend Workflow
DelphiCon
 
IoC and Dependency Injection
DelphiCon
 
No SQL
DelphiCon
 
Effective email communications with a customer
DelphiCon
 
Сборка Front-end’a
DelphiCon
 
React.js
DelphiCon
 
Garbage collector
DelphiCon
 
SOLID
DelphiCon
 
RESTful API and ASP.NET
DelphiCon
 
Ad

Similar to Ruby on Rails (20)

PPTX
Rubyonrails 120409061835-phpapp02
sagaroceanic11
 
PDF
Lecture #5 Introduction to rails
Evgeniy Hinyuk
 
PDF
Introduction to Rails by Evgeniy Hinyuk
Pivorak MeetUp
 
PPTX
Ruby on Rails - An overview
Thomas Asikis
 
PDF
Ruby Rails Web Development
Sonia Simi
 
PDF
Aspose pdf
Jim Jones
 
PDF
FGCU Camp Talk
Mark Brooks
 
KEY
Wed Development on Rails
James Gray
 
PPT
Ruby On Rails Seminar Basis Softexpo Feb2010
arif44
 
KEY
Ruby On Rails
Eric Berry
 
PDF
Ruby Rails Web Development.pdf
Ayesha Siddika
 
PPTX
Why Ruby?
IT Weekend
 
PDF
Ruby on Rails Presentation
Michael MacDonald
 
PPT
Viridians on Rails
Viridians
 
PDF
Introduction to rails
Go Asgard
 
KEY
An introduction to Rails 3
Blazing Cloud
 
PDF
Ruby On Rails
anides
 
PDF
Introduction to Rails - presented by Arman Ortega
arman o
 
KEY
Why ruby and rails
Reuven Lerner
 
PDF
Ruby Rails Overview
Netguru
 
Rubyonrails 120409061835-phpapp02
sagaroceanic11
 
Lecture #5 Introduction to rails
Evgeniy Hinyuk
 
Introduction to Rails by Evgeniy Hinyuk
Pivorak MeetUp
 
Ruby on Rails - An overview
Thomas Asikis
 
Ruby Rails Web Development
Sonia Simi
 
Aspose pdf
Jim Jones
 
FGCU Camp Talk
Mark Brooks
 
Wed Development on Rails
James Gray
 
Ruby On Rails Seminar Basis Softexpo Feb2010
arif44
 
Ruby On Rails
Eric Berry
 
Ruby Rails Web Development.pdf
Ayesha Siddika
 
Why Ruby?
IT Weekend
 
Ruby on Rails Presentation
Michael MacDonald
 
Viridians on Rails
Viridians
 
Introduction to rails
Go Asgard
 
An introduction to Rails 3
Blazing Cloud
 
Ruby On Rails
anides
 
Introduction to Rails - presented by Arman Ortega
arman o
 
Why ruby and rails
Reuven Lerner
 
Ruby Rails Overview
Netguru
 
Ad

Recently uploaded (20)

PDF
20ES1152 Programming for Problem Solving Lab Manual VRSEC.pdf
Ashutosh Satapathy
 
PPTX
澳洲电子毕业证澳大利亚圣母大学水印成绩单UNDA学生证网上可查学历
Taqyea
 
PPTX
Water Resources Engineering (CVE 728)--Slide 3.pptx
mohammedado3
 
PPTX
Numerical-Solutions-of-Ordinary-Differential-Equations.pptx
SAMUKTHAARM
 
PPTX
Water Resources Engineering (CVE 728)--Slide 4.pptx
mohammedado3
 
PDF
aAn_Introduction_to_Arcadia_20150115.pdf
henriqueltorres1
 
PPTX
OCS353 DATA SCIENCE FUNDAMENTALS- Unit 1 Introduction to Data Science
A R SIVANESH M.E., (Ph.D)
 
PPTX
Biosensors, BioDevices, Biomediccal.pptx
AsimovRiyaz
 
PDF
Basic_Concepts_in_Clinical_Biochemistry_2018كيمياء_عملي.pdf
AdelLoin
 
PPTX
美国电子版毕业证南卡罗莱纳大学上州分校水印成绩单USC学费发票定做学位证书编号怎么查
Taqyea
 
PDF
Electrical Engineer operation Supervisor
ssaruntatapower143
 
PDF
AI TECHNIQUES FOR IDENTIFYING ALTERATIONS IN THE HUMAN GUT MICROBIOME IN MULT...
vidyalalltv1
 
PDF
methodology-driven-mbse-murphy-july-hsv-huntsville6680038572db67488e78ff00003...
henriqueltorres1
 
PPTX
Lecture 1 Shell and Tube Heat exchanger-1.pptx
mailforillegalwork
 
PDF
Halide Perovskites’ Multifunctional Properties: Coordination Engineering, Coo...
TaameBerhe2
 
PPTX
DATA BASE MANAGEMENT AND RELATIONAL DATA
gomathisankariv2
 
PPTX
MODULE 04 - CLOUD COMPUTING AND SECURITY.pptx
Alvas Institute of Engineering and technology, Moodabidri
 
PPTX
MODULE 05 - CLOUD COMPUTING AND SECURITY.pptx
Alvas Institute of Engineering and technology, Moodabidri
 
PDF
MODULE-5 notes [BCG402-CG&V] PART-B.pdf
Alvas Institute of Engineering and technology, Moodabidri
 
PDF
Reasons for the succes of MENARD PRESSUREMETER.pdf
majdiamz
 
20ES1152 Programming for Problem Solving Lab Manual VRSEC.pdf
Ashutosh Satapathy
 
澳洲电子毕业证澳大利亚圣母大学水印成绩单UNDA学生证网上可查学历
Taqyea
 
Water Resources Engineering (CVE 728)--Slide 3.pptx
mohammedado3
 
Numerical-Solutions-of-Ordinary-Differential-Equations.pptx
SAMUKTHAARM
 
Water Resources Engineering (CVE 728)--Slide 4.pptx
mohammedado3
 
aAn_Introduction_to_Arcadia_20150115.pdf
henriqueltorres1
 
OCS353 DATA SCIENCE FUNDAMENTALS- Unit 1 Introduction to Data Science
A R SIVANESH M.E., (Ph.D)
 
Biosensors, BioDevices, Biomediccal.pptx
AsimovRiyaz
 
Basic_Concepts_in_Clinical_Biochemistry_2018كيمياء_عملي.pdf
AdelLoin
 
美国电子版毕业证南卡罗莱纳大学上州分校水印成绩单USC学费发票定做学位证书编号怎么查
Taqyea
 
Electrical Engineer operation Supervisor
ssaruntatapower143
 
AI TECHNIQUES FOR IDENTIFYING ALTERATIONS IN THE HUMAN GUT MICROBIOME IN MULT...
vidyalalltv1
 
methodology-driven-mbse-murphy-july-hsv-huntsville6680038572db67488e78ff00003...
henriqueltorres1
 
Lecture 1 Shell and Tube Heat exchanger-1.pptx
mailforillegalwork
 
Halide Perovskites’ Multifunctional Properties: Coordination Engineering, Coo...
TaameBerhe2
 
DATA BASE MANAGEMENT AND RELATIONAL DATA
gomathisankariv2
 
MODULE 04 - CLOUD COMPUTING AND SECURITY.pptx
Alvas Institute of Engineering and technology, Moodabidri
 
MODULE 05 - CLOUD COMPUTING AND SECURITY.pptx
Alvas Institute of Engineering and technology, Moodabidri
 
MODULE-5 notes [BCG402-CG&V] PART-B.pdf
Alvas Institute of Engineering and technology, Moodabidri
 
Reasons for the succes of MENARD PRESSUREMETER.pdf
majdiamz
 

Ruby on Rails

  • 1. SO FOLKSSO FOLKS WANT TOWANT TO YOUYOU
  • 3. SO, RUBY IS...SO, RUBY IS... A dynamic programming language Focused on simplicity and productivity Has an elegant syntax Natural to read and easy to write
  • 4. THE IDEALS OF IT’S CREATORTHE IDEALS OF IT’S CREATOR “ Ruby is simple in appearance, but is very complex inside, just like our human body Yukihiro “Matz” Matsumoto Ruby is a language of careful balance Blended of Perl, Smalltalk, Eiffel, Ada, and Lisp Language that balanced functional programming with imperative programming
  • 5. RUBY’S GROWTHRUBY’S GROWTH Released in 1995 Achieved mass acceptance in 2006 Ranked among the top 10 on most of the indices that measure the growth and popularity of programming languages worldwide
  • 6. DEMAND OF RUBYDEMAND OF RUBY graph by TIOB E
  • 7. EVERYTHING IS AN OBJECTEVERYTHING IS AN OBJECT “ I wanted a scripting language that was more powerful than Perl, and more object-oriented than Python Yukihiro “Matz” Matsumoto In Ruby, everything is an object Object-oriented programming calls properties by the name instance variables and actions are known as methods Ruby follows the influence of the language by giving methods and instance variables to all of its types Smalltalk
  • 8. 5.times { print "We *love* Ruby -- it's outrageous!n" }
  • 9. RUBY’S FLEXIBILITYRUBY’S FLEXIBILITY Ruby is seen as a flexible language It allows its users to freely alter its parts Essential parts can be removed/redefined, at will Existing parts can be added upon Ruby tries not to restrict the coder
  • 10. class Numeric def plus(x) self.+(x) end end y = 5.plus 6 Use the readable word plus to Ruby’s builtin Numeric class
  • 11. BUILT WITH RUBYBUILT WITH RUBY AND RAILSAND RAILS
  • 13. WHAT IS RAILS ?WHAT IS RAILS ? A web application framework written in Ruby Uses model–view–controller (MVC) Provides structures for database/web service/pages JSON or XML for data transfer Rails emphasizes the use of: convention over configuration (CoC) active record pattern don't repeat yourself (DRY)
  • 14. A WORD ABOUT ARA WORD ABOUT AR (Active Record) active record pattern is architectural pattern This is approach to accessing data in a database Interface of this pattern would include: Insert Update Delete + properties that correspond to columns in underlying database table / /
  • 15. SO...SO... In AR database table or view is wrapped into a class Object instance is tied to a single row in the table Object created = new row is added to the table Object updated = row is also updated Object implements accessor methods for each column in the table Object removed = row removed too
  • 16. C# FELLAS MAY CHECKOUT ACTIVEC# FELLAS MAY CHECKOUT ACTIVE RECORD IMPLEMENTATION BYRECORD IMPLEMENTATION BY CASTLECASTLE PROJECTPROJECT::
  • 17. OKAYOKAY LETS GET IT INSTALLEDLETS GET IT INSTALLED
  • 18. FOR LINUXFOR LINUX Or via Ruby Version Manager (RVM) $ sudo apt-get install ruby-full $ curl -sSL https://get.rvm.io | bash -s stable $ rvm install ruby $ rvm use ruby --default $ rvm rubygems current Simply EASY AS HELL Finally $ gem install rails
  • 19. FOR WINDOWSFOR WINDOWS For God's (and your nerves) sake: Go to: Click most inconspicuous button 1. 2. Like this one AND JUST RUN GODDAMN INSTALLATIONAND JUST RUN GODDAMN INSTALLATION
  • 20. FINALLYFINALLY Check all things are installed successfully $ ruby -v ruby 2.0.0p (2015-04-13) IF SO - WE'RE GOOD TO GO $ gem -v 2.4.8 $ rails -v Rails 4.2.3 $ sqlite3 --version 3.8.11.1 2015-07-15....
  • 21. LETS SCAFFOLD !LETS SCAFFOLD ! Create new Rails project in folder `blog` $ rails new blog Install all dependency gems $ bundle install $ cd blog Enter project folder Run Rails server $ rails server $ rails sor
  • 23. WELCOME ABOARDWELCOME ABOARD Folder Description /app controllers, models, views and assets for application /config Application's routes, database, etc. /db Contains database schema and migrations /public Static files and compiled assets /test Unit tests and fixtures /tmp Cache, pid, and session files /vendor Place for all third-party code
  • 24. LETS CLARIFY DOES RAILS USE WHAT STACK
  • 25. eRuby Instead of plain JS To make CSS debugging even more fun Templating system similar to ASP, JSP and PHP Quite unexpected, isn't it ? & To compile into plain JS
  • 26. COFFEESCRIPTCOFFEESCRIPT If you ever wondered how it work square = (x) -> x * x cube = (x) -> square(x) * x alert square 2 var cube, square; square = function(x) { return x * x; }; cube = function(x) { return square(x) * x; }; alert(square(2)); CoffeeScript JavaScript
  • 27. RAILS CLIRAILS CLI There are a few commands of everyday usage. In the order of how much you'll use them are: rails console rails server rake rails generate rails dbconsole rails new app_name All commands can run with -h or --help to list more information.
  • 28. GENERATEGENERATE $ bin/rails generate controller Greetings hello create app/controllers/greetings_controller.rb route get "greetings/hello" invoke erb create app/views/greetings create app/views/greetings/hello.html.erb invoke test_unit create test/controllers/greetings_controller_test.rb invoke helper create app/helpers/greetings_helper.rb invoke assets invoke coffee create app/assets/javascripts/greetings.js.coffee invoke scss create app/assets/stylesheets/greetings.css.scss
  • 29. WE GET THISWE GET THIS class GreetingsController < ApplicationController def hello @message = "Hello, how are you today?" end end app/controllers/greetings_controller.rb <h1>A Greeting for You!</h1> <p><%= @message %></p> app/views/greetings/hello.html.erb
  • 30. RAILS `SCAFFOLD`RAILS `SCAFFOLD` A scaffold in Rails is a full set of: AS A MORE SUITABLE TOOL FOR GENERATING STUFF model database migration for the model controller
  • 31. FOR EXAMPLEFOR EXAMPLE $ bin/rails generate scaffold HighScore game:string score:integer invoke active_record create db/migrate/20130717151933_create_high_scores.rb create app/models/high_score.rb invoke test_unit create test/models/high_score_test.rb create test/fixtures/high_scores.yml invoke resource_route route resources :high_scores invoke scaffold_controller create app/controllers/high_scores_controller.rb invoke erb create app/views/high_scores create app/views/high_scores/index.html.erb create app/views/high_scores/edit.html.erb create app/views/high_scores/show.html.erb create app/views/high_scores/new.html.erb create app/views/high_scores/_form.html.erb ... ... invoke test_unit create test/controllers/high_scores_controller_test.rb invoke helper create app/helpers/high_scores_helper.rb invoke jbuilder create app/views/high_scores/index.json.jbuilder create app/views/high_scores/show.json.jbuilder invoke assets invoke coffee create app/assets/javascripts/high_scores.js.coffee invoke scss create app/assets/stylesheets/high_scores.css.scss invoke scss identical app/assets/stylesheets/scaffolds.css.scss
  • 32. AND RAKEAND RAKE Rake is a Make-like program implemented in Ruby. Except tasks and dependencies are specified in standard Ruby syntax. WE USE RAILS FOR:WE USE RAILS FOR: Running db migrations Seeding database with preset data Getting list of all routes Running test
  • 33. LETS FIND OUT WHAT WE CAN RAKELETS FIND OUT WHAT WE CAN RAKE Simply typing: $ bin/rake --tasks We get: rake about # List versions of all Rails frameworks and the environment rake assets:clean # Remove old compiled assets rake assets:clobber # Remove compiled assets rake assets:precompile # Compile all the assets named in config.assets.precompile rake db:create # Create the database from config/database.yml for the current Rails.en ... rake log:clear # Truncates all *.log files in log/ to zero bytes rake middleware # Prints out your Rack middleware stack ... rake tmp:clear # Clear session, cache, and socket files from tmp/ rake tmp:create # Creates tmp directories for sessions, cache, sockets, and pids
  • 34. AND THATS ALLAND THATS ALL
  • 35. CHECKOUT `HELLO WORLD` REPOCHECKOUT `HELLO WORLD` REPO
  • 36. FURTHER LEARNINGFURTHER LEARNING Ruby Rails GREAT SCREENCASTS:GREAT SCREENCASTS: https://mackenziechild.me/12-in-12/