SlideShare uma empresa Scribd logo
1 de 18
Ruby on Rails Guide – P1
                                      Brady Cheng




http://bradyisstudying.blogspot.tw/
Agenda


Prerequisite
First App
Prerequisite


What is Ruby?
  A programming language
What is Rails?
  A web application framework programmed by Ruby
Prerequisite


           MVC
              Model-View-Controller




              Refer to this slide for other details
                 http://www.slideshare.net/jaceju/mvc-8761203

Img src: http://www.ils.unc.edu/~uskala/MVC.htm
Prerequisite


REST

  CRUD       REST     Note
  Create     Post     New data
  Read       Get      Read data
  Update     Put      Update data
  Delete     Delete   Delete data
Prerequisite


Installation
  Windows base
    http://railsinstaller.org/
  Trouble shooting
    ERROR: Error installing json: The 'json' native gem requires
    installed build tools.
    http://stackoverflow.com/questions/8100891/the-json-
    native-gem-requires-installed-build-tools
Prerequisite


Create a new project
  rails new your_project_name

Start the created project
  cd project_name
  bundle install
  rails server
  Check http://localhost:3000 or http://127.0.0.1:3000
Prerequisite


Project organization
  /app
    Organize your models, views, and controllers
  /config
    Configs such as database config (database.yml), rails
    environmental config (environment.rb)…etc
  /db
    Manage your database
Prerequisite


Project organization
  /doc
     Docs generated by RubyDoc framework
  /lib
     Libs for your applications
  /log
     Error log such as “server.log”, “development.log”…etc
  /public
     Some html files for your applications
Prerequisite


Project organization
  /script
    Some scripts for your applications
  /test
    Some tests written by you or by rails such as unit
    test, fixture tests…etc.
  /tmp
    Temp files
  /vendor
    Third party libs
Prerequisite


Snapshot
First App


We can use the following command to new a
controller and related files
      rails generate GENERATOR ARG


Generator can be assets, controller, helper…etc
ARG here is the file name
First App


Snapshot of the responses
First App


           Testing your http://127.0.0.1:3000/greeting




           Edit your config/routes.rb
                         resources :greeting


http://stackoverflow.com/questions/11696695/routing-error-ruby-on-rails
First App


After updating the routes.rb




Add an index function in your controller
def index
   render :text=>”Hello Ruby world!”
end
First App


Aforementioned approach is somehow dirty
  We need to follow the MVC rules

Update the index function in controller
  def index
    @welcome_msg = "Hello RoR world“
  end
Update view/index.html/erb
  <%= @welcome_msg %>
First App


Worth to mention what erb file is

ERB file = html code + ruby code
  Ruby code will be surrounded by <%...%> or <%=…%>
    <% code here %> : pure logic, nothing display to screen
    <%= code here %> : display something to screen
First App


Worth to mention the Request scope

Request scope
  Each http request will get a copy of the controller
    Pros : thread safe
    Cons: hard to share data between different requests
      Solution: use sessions

Mais conteúdo relacionado

Mais procurados

Web service with Laravel
Web service with LaravelWeb service with Laravel
Web service with LaravelAbuzer Firdousi
 
RESTful API development in Laravel 4 - Christopher Pecoraro
RESTful API development in Laravel 4 - Christopher PecoraroRESTful API development in Laravel 4 - Christopher Pecoraro
RESTful API development in Laravel 4 - Christopher PecoraroChristopher Pecoraro
 
Laravel 5 Annotations: RESTful API routing
Laravel 5 Annotations: RESTful API routingLaravel 5 Annotations: RESTful API routing
Laravel 5 Annotations: RESTful API routingChristopher Pecoraro
 
Introduction to laravel framework
Introduction to laravel frameworkIntroduction to laravel framework
Introduction to laravel frameworkAhmad Fatoni
 
Laravel & Composer presentation - extended
Laravel & Composer presentation - extendedLaravel & Composer presentation - extended
Laravel & Composer presentation - extendedCvetomir Denchev
 
Top laravel packages to install handpicked list from expert
Top laravel packages to install handpicked list from expertTop laravel packages to install handpicked list from expert
Top laravel packages to install handpicked list from expertKaty Slemon
 
php[world] 2015 Laravel 5.1: From Homestead to the Cloud
php[world] 2015 Laravel 5.1: From Homestead to the Cloudphp[world] 2015 Laravel 5.1: From Homestead to the Cloud
php[world] 2015 Laravel 5.1: From Homestead to the CloudJoe Ferguson
 
How to dockerize rails application compose and rails tutorial
How to dockerize rails application compose and rails tutorialHow to dockerize rails application compose and rails tutorial
How to dockerize rails application compose and rails tutorialKaty Slemon
 
Clustering Multiple Instances in Cold Fusion
Clustering Multiple Instances in Cold FusionClustering Multiple Instances in Cold Fusion
Clustering Multiple Instances in Cold FusionMindfire Solutions
 
Laravel Beginners Tutorial 2
Laravel Beginners Tutorial 2Laravel Beginners Tutorial 2
Laravel Beginners Tutorial 2Vikas Chauhan
 
Task scheduling in laravel 8 tutorial
Task scheduling in laravel 8 tutorialTask scheduling in laravel 8 tutorial
Task scheduling in laravel 8 tutorialKaty Slemon
 

Mais procurados (20)

Web service with Laravel
Web service with LaravelWeb service with Laravel
Web service with Laravel
 
RESTful API development in Laravel 4 - Christopher Pecoraro
RESTful API development in Laravel 4 - Christopher PecoraroRESTful API development in Laravel 4 - Christopher Pecoraro
RESTful API development in Laravel 4 - Christopher Pecoraro
 
Rails onCpanel
Rails onCpanelRails onCpanel
Rails onCpanel
 
Laravel 5 Annotations: RESTful API routing
Laravel 5 Annotations: RESTful API routingLaravel 5 Annotations: RESTful API routing
Laravel 5 Annotations: RESTful API routing
 
Introduction to laravel framework
Introduction to laravel frameworkIntroduction to laravel framework
Introduction to laravel framework
 
Laravel overview
Laravel overviewLaravel overview
Laravel overview
 
CakePHP REST Plugin
CakePHP REST PluginCakePHP REST Plugin
CakePHP REST Plugin
 
Laravel Tutorial PPT
Laravel Tutorial PPTLaravel Tutorial PPT
Laravel Tutorial PPT
 
Why Laravel?
Why Laravel?Why Laravel?
Why Laravel?
 
Javascript laravel's friend
Javascript laravel's friendJavascript laravel's friend
Javascript laravel's friend
 
Laravel & Composer presentation - extended
Laravel & Composer presentation - extendedLaravel & Composer presentation - extended
Laravel & Composer presentation - extended
 
Top laravel packages to install handpicked list from expert
Top laravel packages to install handpicked list from expertTop laravel packages to install handpicked list from expert
Top laravel packages to install handpicked list from expert
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
php[world] 2015 Laravel 5.1: From Homestead to the Cloud
php[world] 2015 Laravel 5.1: From Homestead to the Cloudphp[world] 2015 Laravel 5.1: From Homestead to the Cloud
php[world] 2015 Laravel 5.1: From Homestead to the Cloud
 
Laravel 5.4
Laravel 5.4 Laravel 5.4
Laravel 5.4
 
How to dockerize rails application compose and rails tutorial
How to dockerize rails application compose and rails tutorialHow to dockerize rails application compose and rails tutorial
How to dockerize rails application compose and rails tutorial
 
Clustering Multiple Instances in Cold Fusion
Clustering Multiple Instances in Cold FusionClustering Multiple Instances in Cold Fusion
Clustering Multiple Instances in Cold Fusion
 
Intro to Laravel
Intro to LaravelIntro to Laravel
Intro to Laravel
 
Laravel Beginners Tutorial 2
Laravel Beginners Tutorial 2Laravel Beginners Tutorial 2
Laravel Beginners Tutorial 2
 
Task scheduling in laravel 8 tutorial
Task scheduling in laravel 8 tutorialTask scheduling in laravel 8 tutorial
Task scheduling in laravel 8 tutorial
 

Destaque

Ruby introduction part1
Ruby introduction part1Ruby introduction part1
Ruby introduction part1Brady Cheng
 
Javascipt ch4 & ch5
Javascipt ch4 & ch5Javascipt ch4 & ch5
Javascipt ch4 & ch5Brady Cheng
 
design pattern overview
design pattern overviewdesign pattern overview
design pattern overviewBrady Cheng
 

Destaque (9)

Javascript ch3
Javascript ch3Javascript ch3
Javascript ch3
 
Ruby introduction part1
Ruby introduction part1Ruby introduction part1
Ruby introduction part1
 
Javascipt ch4 & ch5
Javascipt ch4 & ch5Javascipt ch4 & ch5
Javascipt ch4 & ch5
 
Javascript ch8
Javascript ch8Javascript ch8
Javascript ch8
 
Javascript ch2
Javascript ch2Javascript ch2
Javascript ch2
 
Javascipt ch1
Javascipt ch1Javascipt ch1
Javascipt ch1
 
Javascript ch6
Javascript ch6Javascript ch6
Javascript ch6
 
design pattern overview
design pattern overviewdesign pattern overview
design pattern overview
 
Javascript ch7
Javascript ch7Javascript ch7
Javascript ch7
 

Semelhante a RoR guide_p1

Ruby On Rails
Ruby On RailsRuby On Rails
Ruby On Railsanides
 
Red5workshop 090619073420-phpapp02
Red5workshop 090619073420-phpapp02Red5workshop 090619073420-phpapp02
Red5workshop 090619073420-phpapp02arghya007
 
Building Application with Ruby On Rails Framework
Building Application with Ruby On Rails FrameworkBuilding Application with Ruby On Rails Framework
Building Application with Ruby On Rails FrameworkEdureka!
 
Rails Engine | Modular application
Rails Engine | Modular applicationRails Engine | Modular application
Rails Engine | Modular applicationmirrec
 
Developing Java Web Applications
Developing Java Web ApplicationsDeveloping Java Web Applications
Developing Java Web Applicationshchen1
 
Ruby On Rails Basics
Ruby On Rails BasicsRuby On Rails Basics
Ruby On Rails BasicsAmit Solanki
 
Rails
RailsRails
RailsSHC
 
Building web framework with Rack
Building web framework with RackBuilding web framework with Rack
Building web framework with Racksickill
 
Java servlet technology
Java servlet technologyJava servlet technology
Java servlet technologyMinal Maniar
 
eXo Platform SEA - Play Framework Introduction
eXo Platform SEA - Play Framework IntroductioneXo Platform SEA - Play Framework Introduction
eXo Platform SEA - Play Framework Introductionvstorm83
 
Play Framework: async I/O with Java and Scala
Play Framework: async I/O with Java and ScalaPlay Framework: async I/O with Java and Scala
Play Framework: async I/O with Java and ScalaYevgeniy Brikman
 

Semelhante a RoR guide_p1 (20)

Dev streams2
Dev streams2Dev streams2
Dev streams2
 
Ruby On Rails
Ruby On RailsRuby On Rails
Ruby On Rails
 
Red5 - PHUG Workshops
Red5 - PHUG WorkshopsRed5 - PHUG Workshops
Red5 - PHUG Workshops
 
Red5workshop 090619073420-phpapp02
Red5workshop 090619073420-phpapp02Red5workshop 090619073420-phpapp02
Red5workshop 090619073420-phpapp02
 
Intro to Rack
Intro to RackIntro to Rack
Intro to Rack
 
Aspose pdf
Aspose pdfAspose pdf
Aspose pdf
 
Building Application with Ruby On Rails Framework
Building Application with Ruby On Rails FrameworkBuilding Application with Ruby On Rails Framework
Building Application with Ruby On Rails Framework
 
Rails Engine | Modular application
Rails Engine | Modular applicationRails Engine | Modular application
Rails Engine | Modular application
 
Developing Java Web Applications
Developing Java Web ApplicationsDeveloping Java Web Applications
Developing Java Web Applications
 
Ruby On Rails Basics
Ruby On Rails BasicsRuby On Rails Basics
Ruby On Rails Basics
 
Ruby On Rails
Ruby On RailsRuby On Rails
Ruby On Rails
 
TorqueBox
TorqueBoxTorqueBox
TorqueBox
 
Rails
RailsRails
Rails
 
Building web framework with Rack
Building web framework with RackBuilding web framework with Rack
Building web framework with Rack
 
Java servlet technology
Java servlet technologyJava servlet technology
Java servlet technology
 
eXo Platform SEA - Play Framework Introduction
eXo Platform SEA - Play Framework IntroductioneXo Platform SEA - Play Framework Introduction
eXo Platform SEA - Play Framework Introduction
 
Play Framework: async I/O with Java and Scala
Play Framework: async I/O with Java and ScalaPlay Framework: async I/O with Java and Scala
Play Framework: async I/O with Java and Scala
 
Supa fast Ruby + Rails
Supa fast Ruby + RailsSupa fast Ruby + Rails
Supa fast Ruby + Rails
 
BPMS1
BPMS1BPMS1
BPMS1
 
BPMS1
BPMS1BPMS1
BPMS1
 

RoR guide_p1

  • 1. Ruby on Rails Guide – P1 Brady Cheng http://bradyisstudying.blogspot.tw/
  • 3. Prerequisite What is Ruby? A programming language What is Rails? A web application framework programmed by Ruby
  • 4. Prerequisite MVC Model-View-Controller Refer to this slide for other details http://www.slideshare.net/jaceju/mvc-8761203 Img src: http://www.ils.unc.edu/~uskala/MVC.htm
  • 5. Prerequisite REST CRUD REST Note Create Post New data Read Get Read data Update Put Update data Delete Delete Delete data
  • 6. Prerequisite Installation Windows base http://railsinstaller.org/ Trouble shooting ERROR: Error installing json: The 'json' native gem requires installed build tools. http://stackoverflow.com/questions/8100891/the-json- native-gem-requires-installed-build-tools
  • 7. Prerequisite Create a new project rails new your_project_name Start the created project cd project_name bundle install rails server Check http://localhost:3000 or http://127.0.0.1:3000
  • 8. Prerequisite Project organization /app Organize your models, views, and controllers /config Configs such as database config (database.yml), rails environmental config (environment.rb)…etc /db Manage your database
  • 9. Prerequisite Project organization /doc Docs generated by RubyDoc framework /lib Libs for your applications /log Error log such as “server.log”, “development.log”…etc /public Some html files for your applications
  • 10. Prerequisite Project organization /script Some scripts for your applications /test Some tests written by you or by rails such as unit test, fixture tests…etc. /tmp Temp files /vendor Third party libs
  • 12. First App We can use the following command to new a controller and related files rails generate GENERATOR ARG Generator can be assets, controller, helper…etc ARG here is the file name
  • 13. First App Snapshot of the responses
  • 14. First App Testing your http://127.0.0.1:3000/greeting Edit your config/routes.rb resources :greeting http://stackoverflow.com/questions/11696695/routing-error-ruby-on-rails
  • 15. First App After updating the routes.rb Add an index function in your controller def index render :text=>”Hello Ruby world!” end
  • 16. First App Aforementioned approach is somehow dirty We need to follow the MVC rules Update the index function in controller def index @welcome_msg = "Hello RoR world“ end Update view/index.html/erb <%= @welcome_msg %>
  • 17. First App Worth to mention what erb file is ERB file = html code + ruby code Ruby code will be surrounded by <%...%> or <%=…%> <% code here %> : pure logic, nothing display to screen <%= code here %> : display something to screen
  • 18. First App Worth to mention the Request scope Request scope Each http request will get a copy of the controller Pros : thread safe Cons: hard to share data between different requests Solution: use sessions