SlideShare una empresa de Scribd logo
1 de 37
Ruby on RailsJune 17, 2011Elpizo Choi
What is Ruby on Rails? MVC Framework for building web apps in Ruby Uses Ruby classes to abstract out the various components of an app Convention over configuration
Main Components ActiveRecord(ORM – think hibernate) ActionController(business logic, routing) ActionView(template parser) Migrations, rake tasks
Creating a Rails app
Basic folder structure apps folder controllers, models, views – where you’ll spend most your time database.yml Configures database Gemfile Configures external libraries used in app
… a little configuration
…a little configuration
Let’s make a model
ActiveRecord::Base When inherited, maps to table that’s plural of class name Team -> teams Basic methods Team.create() Team.find() Team.where().limit().sort().skip().first Team.where().limit().sort().skip().all
…first we need to create table
…first we need to create table
…first we need to create table Rake ,[object Object]
rake –T to see all available tasks
rake db:migrate will run all database migrations that haven’t been run
Stores migrations that have already been run,[object Object]
Querying More in-depth tutorial:   http://guides.rubyonrails.org/active_record_querying.html
The “web” part of web-app
Let’s get this running
What happened?
What happened?
What happened? config/routes.rb defines how urls are mapped to controllers get “teams/index” is shorthand for: match “teams/index” => “teams#index”, :via => :get More details: http://guides.rubyonrails.org/routing.html Read comments in config/routes.rb
Let’s make some changes
Let’s make some changes
Let’s make some changes
Controller ,[object Object]
All code in the corresponding method will happen as side effects
Instanced variables set here are available to the template,[object Object]
Add as extension to allow the default Rails template engine to parse Ruby code inside HTML,[object Object]
<% %> tag:  Ruby code to be run, but not shown
<%= %>tag: Ruby code to be run and shown
^^ important: because everything in Ruby returns something (in this case it’ll be @team object from the block),[object Object]
Creating relationships Create the player Add foreign key
Creating relationships
Creating relationships Gotta reload console after changing models Get players
But wait!  There’s a shortcut! has_many basically does the following: ,[object Object]
for records whose foreign key column corresponds to the current class (team_id)
and where the value is the current instance id (1),[object Object]

Más contenido relacionado

La actualidad más candente

LINQ Inside
LINQ InsideLINQ Inside
LINQ Inside
jeffz
 

La actualidad más candente (20)

Arrays &amp; functions in php
Arrays &amp; functions in phpArrays &amp; functions in php
Arrays &amp; functions in php
 
Recipes to build Code Generators for Non-Xtext Models with Xtend
Recipes to build Code Generators for Non-Xtext Models with XtendRecipes to build Code Generators for Non-Xtext Models with Xtend
Recipes to build Code Generators for Non-Xtext Models with Xtend
 
Reference Semantik mit C# und .NET Core - BASTA 2019
Reference Semantik mit C# und .NET Core - BASTA 2019Reference Semantik mit C# und .NET Core - BASTA 2019
Reference Semantik mit C# und .NET Core - BASTA 2019
 
LINQ Inside
LINQ InsideLINQ Inside
LINQ Inside
 
Introduction to underscore.js
Introduction to underscore.jsIntroduction to underscore.js
Introduction to underscore.js
 
JavaScript operators
JavaScript operatorsJavaScript operators
JavaScript operators
 
Underscore
UnderscoreUnderscore
Underscore
 
Ruby Interview Questions
Ruby Interview QuestionsRuby Interview Questions
Ruby Interview Questions
 
Dutch hug
Dutch hugDutch hug
Dutch hug
 
#Pharo Days 2016 Data Formats and Protocols
#Pharo Days 2016 Data Formats and Protocols#Pharo Days 2016 Data Formats and Protocols
#Pharo Days 2016 Data Formats and Protocols
 
C# What's next? (7.x and 8.0)
C# What's next? (7.x and 8.0)C# What's next? (7.x and 8.0)
C# What's next? (7.x and 8.0)
 
Apache Velocity
Apache VelocityApache Velocity
Apache Velocity
 
Mini Rails Framework
Mini Rails FrameworkMini Rails Framework
Mini Rails Framework
 
From Ruby to Scala
From Ruby to ScalaFrom Ruby to Scala
From Ruby to Scala
 
Codegeneration With Xtend
Codegeneration With XtendCodegeneration With Xtend
Codegeneration With Xtend
 
PHP 8: What's New and Changed
PHP 8: What's New and ChangedPHP 8: What's New and Changed
PHP 8: What's New and Changed
 
Apache Flink - A Sneek Preview on Language Integrated Queries
Apache Flink - A Sneek Preview on Language Integrated QueriesApache Flink - A Sneek Preview on Language Integrated Queries
Apache Flink - A Sneek Preview on Language Integrated Queries
 
Play framework training by Neelkanth Sachdeva @ Scala traits event , New Delh...
Play framework training by Neelkanth Sachdeva @ Scala traits event , New Delh...Play framework training by Neelkanth Sachdeva @ Scala traits event , New Delh...
Play framework training by Neelkanth Sachdeva @ Scala traits event , New Delh...
 
Code documentation
Code documentationCode documentation
Code documentation
 
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
 

Destacado

Vitamin c and the common cold
Vitamin c and the common coldVitamin c and the common cold
Vitamin c and the common cold
Corrie T
 
Chineese smuggling
Chineese smugglingChineese smuggling
Chineese smuggling
grigor545
 

Destacado (14)

Matrizes e determinantes
Matrizes e determinantesMatrizes e determinantes
Matrizes e determinantes
 
Jose victor patiño duran - curriculum
Jose victor patiño duran -  curriculumJose victor patiño duran -  curriculum
Jose victor patiño duran - curriculum
 
WordCamp Northeast Ohio The Designers Toolkit
WordCamp Northeast Ohio   The Designers ToolkitWordCamp Northeast Ohio   The Designers Toolkit
WordCamp Northeast Ohio The Designers Toolkit
 
Playing Like a Girl
Playing Like a GirlPlaying Like a Girl
Playing Like a Girl
 
Redes sociales
Redes sociales Redes sociales
Redes sociales
 
Malnutrition in the hospital
Malnutrition in the hospitalMalnutrition in the hospital
Malnutrition in the hospital
 
One hundred million dollars
One hundred million dollarsOne hundred million dollars
One hundred million dollars
 
One hundred million dollars
One hundred million dollarsOne hundred million dollars
One hundred million dollars
 
Vitamin c and the common cold
Vitamin c and the common coldVitamin c and the common cold
Vitamin c and the common cold
 
2012 AAA Cavalier Bremworth Unbuilt Architecture Awards
2012 AAA Cavalier Bremworth Unbuilt Architecture Awards2012 AAA Cavalier Bremworth Unbuilt Architecture Awards
2012 AAA Cavalier Bremworth Unbuilt Architecture Awards
 
Chineese smuggling
Chineese smugglingChineese smuggling
Chineese smuggling
 
A low carbohydrate mediterranean diet improves cardiovascular risk factors a...
A  low carbohydrate mediterranean diet improves cardiovascular risk factors a...A  low carbohydrate mediterranean diet improves cardiovascular risk factors a...
A low carbohydrate mediterranean diet improves cardiovascular risk factors a...
 
Celebrate life issue25
Celebrate life issue25Celebrate life issue25
Celebrate life issue25
 
2 sumandos-de-2-y-1-dígito (1)
2 sumandos-de-2-y-1-dígito (1)2 sumandos-de-2-y-1-dígito (1)
2 sumandos-de-2-y-1-dígito (1)
 

Similar a Intro to Ruby on Rails

Ruby On Rails Tutorial
Ruby On Rails TutorialRuby On Rails Tutorial
Ruby On Rails Tutorial
sunniboy
 
Introduction to Ruby on Rails
Introduction to Ruby on RailsIntroduction to Ruby on Rails
Introduction to Ruby on Rails
Manoj Kumar
 
An introduction-to-ruby-on-rails
An introduction-to-ruby-on-railsAn introduction-to-ruby-on-rails
An introduction-to-ruby-on-rails
vinicorp
 
An Introduction to Ruby on Rails 20100506
An Introduction to Ruby on Rails 20100506An Introduction to Ruby on Rails 20100506
An Introduction to Ruby on Rails 20100506
Vu Hung Nguyen
 
Rails
RailsRails
Rails
SHC
 

Similar a Intro to Ruby on Rails (20)

Ruby on Rails introduction
Ruby on Rails introduction Ruby on Rails introduction
Ruby on Rails introduction
 
Ruby On Rails
Ruby On RailsRuby On Rails
Ruby On Rails
 
Ruby on rails for beginers
Ruby on rails for beginersRuby on rails for beginers
Ruby on rails for beginers
 
RoR 101: Session 2
RoR 101: Session 2RoR 101: Session 2
RoR 101: Session 2
 
Ruby On Rails Tutorial
Ruby On Rails TutorialRuby On Rails Tutorial
Ruby On Rails Tutorial
 
Ruby on rails
Ruby on railsRuby on rails
Ruby on rails
 
Ruby On Rails
Ruby On RailsRuby On Rails
Ruby On Rails
 
Introduction to Ruby on Rails
Introduction to Ruby on RailsIntroduction to Ruby on Rails
Introduction to Ruby on Rails
 
Ruby On Rails Intro
Ruby On Rails IntroRuby On Rails Intro
Ruby On Rails Intro
 
Supa fast Ruby + Rails
Supa fast Ruby + RailsSupa fast Ruby + Rails
Supa fast Ruby + Rails
 
Introduction To Ruby On Rails
Introduction To Ruby On RailsIntroduction To Ruby On Rails
Introduction To Ruby On Rails
 
Ruby On Rails Introduction
Ruby On Rails IntroductionRuby On Rails Introduction
Ruby On Rails Introduction
 
Intro to Rails and MVC
Intro to Rails and MVCIntro to Rails and MVC
Intro to Rails and MVC
 
Ruby on rails
Ruby on railsRuby on rails
Ruby on rails
 
Ruby on Rails
Ruby on Rails Ruby on Rails
Ruby on Rails
 
Ruby on rails
Ruby on railsRuby on rails
Ruby on rails
 
An introduction-to-ruby-on-rails
An introduction-to-ruby-on-railsAn introduction-to-ruby-on-rails
An introduction-to-ruby-on-rails
 
An Introduction to Ruby on Rails 20100506
An Introduction to Ruby on Rails 20100506An Introduction to Ruby on Rails 20100506
An Introduction to Ruby on Rails 20100506
 
Rails
RailsRails
Rails
 
What's new and great in Rails 3 - Matt Gauger - Milwaukee Ruby Users Group De...
What's new and great in Rails 3 - Matt Gauger - Milwaukee Ruby Users Group De...What's new and great in Rails 3 - Matt Gauger - Milwaukee Ruby Users Group De...
What's new and great in Rails 3 - Matt Gauger - Milwaukee Ruby Users Group De...
 

Último

Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Peter Udo Diehl
 
Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for Success
UXDXConf
 

Último (20)

Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdfLinux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
 
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptxWSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
 
Google I/O Extended 2024 Warsaw
Google I/O Extended 2024 WarsawGoogle I/O Extended 2024 Warsaw
Google I/O Extended 2024 Warsaw
 
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
 
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdfSimplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
 
10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka Doktorová10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka Doktorová
 
Oauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoftOauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoft
 
What's New in Teams Calling, Meetings and Devices April 2024
What's New in Teams Calling, Meetings and Devices April 2024What's New in Teams Calling, Meetings and Devices April 2024
What's New in Teams Calling, Meetings and Devices April 2024
 
PLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. StartupsPLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. Startups
 
The Metaverse: Are We There Yet?
The  Metaverse:    Are   We  There  Yet?The  Metaverse:    Are   We  There  Yet?
The Metaverse: Are We There Yet?
 
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
 
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
 
Enterprise Knowledge Graphs - Data Summit 2024
Enterprise Knowledge Graphs - Data Summit 2024Enterprise Knowledge Graphs - Data Summit 2024
Enterprise Knowledge Graphs - Data Summit 2024
 
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
 
Strategic AI Integration in Engineering Teams
Strategic AI Integration in Engineering TeamsStrategic AI Integration in Engineering Teams
Strategic AI Integration in Engineering Teams
 
AI presentation and introduction - Retrieval Augmented Generation RAG 101
AI presentation and introduction - Retrieval Augmented Generation RAG 101AI presentation and introduction - Retrieval Augmented Generation RAG 101
AI presentation and introduction - Retrieval Augmented Generation RAG 101
 
Connecting the Dots in Product Design at KAYAK
Connecting the Dots in Product Design at KAYAKConnecting the Dots in Product Design at KAYAK
Connecting the Dots in Product Design at KAYAK
 
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
 
Powerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara LaskowskaPowerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara Laskowska
 
Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for Success
 

Intro to Ruby on Rails