SlideShare a Scribd company logo
1 of 41
Download to read offline
Introduction to Ruby-
on-Rails
Evgeniy Hinyuk
Ruby-developer
Github Twitter
Who am I?
Photo taken:
1.07.2016
self-educated
junior
ruby-developer
Now
RAILS
What is Rails?
• Ruby on Rails is an extremely productive web
application framework written in Ruby by
David Heinemeier Hansson in 2005.
• You could develop a web application at least
ten times faster with Rails than you could
with a typical Java framework.
• An open source Ruby framework for
developing database-backed web
applications.
• No compilation phase required.
• Full-stack framework.
• Convention over Configuration
Full-stack framework.
•Includes everything needed to create a database-driven
web application, using the Model-View-Controller
pattern.
•Being a full-stack framework means all the layers are
built to work seamlessly together with less code.
•Requires fewer lines of code than other frameworks.
MVC
Convention over Configuration
•Rails shuns configuration files in favor of conventions,
reflection, and dynamic runtime extensions.
•Your application code and your running database
already contain everything that Rails needs to know! 

Rails Strengths
•Ruby
•Metaprogramming
•DRY
•Active Record
•Convention over Configuration
•Scaffolding
•Built-in testing
•Three environments
•Fun

Rails installation
Rails server
App directory structure
• app - main app directory
• bin - rails needed scripts
• config - configurations for environment, routes,
etc.
• db - schema.db, migrations
• lib - folder for code not included in main app (like
your own gems)
• log - log files
• public - assets for public access, 404 page etc.
• test(spec) - test files
• tmp - place for temporary files
• vendor -folder used for third-party libraries.
Gemfile
A Gemfile is a file
which is used for
describing gem
dependencies for
Ruby programs.
What is Gemfile?
Scaffolding
Development Workflow
• Use the rails command to create the basic skeleton of the application.
• Create a database on the MySQL server to hold your data.
• Configure the application to know where your database is located and the login
credentials for it.
• Create Rails Active Records (Models), because they are the business objects
you'll be working with in your controllers.
• Generate Migrations that simplify the creating and maintaining of database tables
and columns.
• Write Controller Code to put a life in your application.
• Create Views to present your data through User Interface. us start with creating
our library application.
Rails and DB
ActiveRecord
• Rails Active Record is the Object/Relational Mapping (ORM) layer
supplied with Rails.
• Each Active Record object has CRUD methods for database access
Associations
Active Record supports three types of
associations:
• One-to-one (has_one);
• One-to-many (has_many);
• Many-to-many (has_and_belongs_to_many,
polymorphic);
Model in DB
• Each entity (such as book) gets a table in the database named after
it, but in the plural (books).
•  Each such entity-matching table has a field called id, which contains a
unique integer for each record inserted into the table.
• Given entity x and entity y, if entity y belongs to entity x, then table y
has a field called x_id.
• The bulk of the fields in any table store the values for that entity's
simple properties (anything that's a number or a string).
Validations
The implementation of validations is done in a
Rails model. The data you are entering into the
database is defined in the actual Rails model, so it
only makes sense to define what valid data
entails in the same location. Also you can provide
custom validations.
Migrations
Rails Migration allows you to use Ruby to define
changes to your database schema, making it possible
to use a version control system to keep things
synchronized with the actual code.
Migrations
Routes
The routing module
provides URL rewriting in
native Ruby. It's a way to
redirect incoming
requests to controllers
and actions. Best of all,
Rails' Routing works with
any web server.
Routes are defined in:
app/config/routes.rb
`
Rails named routes starts
with HTTP verb. It
supports all the verbs
such as: GET, POST,
PUTPATCH, DELETE.
Routes
Also rails have a special
route for root path.
You can match any url
to any action.
Resourceful Routes
Nested Routes
Controller
The Rails controller is the
logical center of your
application. It coordinates the
interaction between the user,
the views, and the model.
Controller
CRUD
Strong params
It provides an interface for
protecting attributes from end-
user assignment. This makes
Action Controller parameters
forbidden to be used in Active
Model mass assignment until
they have been whitelisted.
Action View
In Rails, web requests are handled by Action Controller and Action View. Typically,
Action Controller is concerned with communicating with the database and performing
CRUD actions where necessary. Action View is then responsible for compiling the
response.
Action View templates are written using embedded Ruby in tags mingled with HTML.
Layout
Use multiple layouts
Helpers
The Rails framework provides a
large number of helpers for
working with assets, dates,
forms, numbers and model
objects, to name a few. These
helpers are available to all
templates by default.
In addition to using the
standard template helpers
provided, creating custom
helpers to extract complicated
logic or reusable functionality
is strongly encouraged.
Rails advanced
A lot of
USEFULL
gems
Testing
How we test rails app
• Unit tests
• Functional tests
• Integration tests
• Rspec
• Factory Girl
• Cucumber
• Capybara
• Minitest
…
Books
1. Ruby on Rails tutorial
2. Well-Grounded Rubyist
3. Rails 4 Way
Conclusion
•Rails is good for prototyping and quick development
•Rails is fun!
•Rails is full-stack framework based on ruby
Thank you for your listening
Questions?
Homework
Write a simple web app which allows you to create an
event(bbq, pizza-day, or etc.). Add credentials to it (place, date,
etc…). Add two roles, admin, and attendee. Admin can add an
event, delete event, add a description, edit an event, add
comments to the event. The attendee can join an event, can
leave an event, can add comments to the event. You will need to
cover it by your preferred test framework and deploy to Heroku.

More Related Content

What's hot

RavenDB Presentation
RavenDB PresentationRavenDB Presentation
RavenDB Presentation
Mark Rodseth
 
NoSQL Database in .NET Apps
NoSQL Database in .NET AppsNoSQL Database in .NET Apps
NoSQL Database in .NET Apps
Shiju Varghese
 

What's hot (18)

Azure App Configuration with .NET applications
Azure App Configuration with .NET applicationsAzure App Configuration with .NET applications
Azure App Configuration with .NET applications
 
Oak, the architecture of Apache Jackrabbit 3
Oak, the architecture of Apache Jackrabbit 3Oak, the architecture of Apache Jackrabbit 3
Oak, the architecture of Apache Jackrabbit 3
 
Indic threads pune12-typesafe stack software development on the jvm
Indic threads pune12-typesafe stack software development on the jvmIndic threads pune12-typesafe stack software development on the jvm
Indic threads pune12-typesafe stack software development on the jvm
 
Dotnet- An overview of ASP.NET & ADO.NET- Mazenet solution
Dotnet- An overview of ASP.NET & ADO.NET- Mazenet solutionDotnet- An overview of ASP.NET & ADO.NET- Mazenet solution
Dotnet- An overview of ASP.NET & ADO.NET- Mazenet solution
 
Asp #2
Asp #2Asp #2
Asp #2
 
Asp.net
Asp.netAsp.net
Asp.net
 
SpringPeople Introduction to MongoDB Administration
SpringPeople Introduction to MongoDB AdministrationSpringPeople Introduction to MongoDB Administration
SpringPeople Introduction to MongoDB Administration
 
Practical Cross-Dataset Queries with SPARQL (Introduction)
Practical Cross-Dataset Queries with SPARQL (Introduction)Practical Cross-Dataset Queries with SPARQL (Introduction)
Practical Cross-Dataset Queries with SPARQL (Introduction)
 
【EDD Workshop@140829】iOS Models-Core Data_by Boska-Lee
【EDD Workshop@140829】iOS Models-Core Data_by Boska-Lee【EDD Workshop@140829】iOS Models-Core Data_by Boska-Lee
【EDD Workshop@140829】iOS Models-Core Data_by Boska-Lee
 
RESTful Web Service using Swagger
RESTful Web Service using SwaggerRESTful Web Service using Swagger
RESTful Web Service using Swagger
 
Skillwise - Advanced web application development
Skillwise - Advanced web application developmentSkillwise - Advanced web application development
Skillwise - Advanced web application development
 
D2RQ
D2RQD2RQ
D2RQ
 
RavenDB Presentation
RavenDB PresentationRavenDB Presentation
RavenDB Presentation
 
NoSQL Database in .NET Apps
NoSQL Database in .NET AppsNoSQL Database in .NET Apps
NoSQL Database in .NET Apps
 
Scala and Lift
Scala and LiftScala and Lift
Scala and Lift
 
Melbourne User Group OAK and MongoDB
Melbourne User Group OAK and MongoDBMelbourne User Group OAK and MongoDB
Melbourne User Group OAK and MongoDB
 
ECS19 - Laura Kokkarinen - Everything you need to know about SharePoint site ...
ECS19 - Laura Kokkarinen - Everything you need to know about SharePoint site ...ECS19 - Laura Kokkarinen - Everything you need to know about SharePoint site ...
ECS19 - Laura Kokkarinen - Everything you need to know about SharePoint site ...
 
WCM-7 Surfing with CMIS
WCM-7 Surfing with CMISWCM-7 Surfing with CMIS
WCM-7 Surfing with CMIS
 

Similar to Lecture #5 Introduction to rails

Jasig rubyon rails
Jasig rubyon railsJasig rubyon rails
Jasig rubyon rails
_zaMmer_
 
Jasig rubyon rails
Jasig rubyon railsJasig rubyon rails
Jasig rubyon rails
_zaMmer_
 
Ruby Rails Web Development.pdf
Ruby Rails Web Development.pdfRuby Rails Web Development.pdf
Ruby Rails Web Development.pdf
Ayesha Siddika
 
Rails
RailsRails
Rails
SHC
 
Service-Oriented Design and Implement with Rails3
Service-Oriented Design and Implement with Rails3Service-Oriented Design and Implement with Rails3
Service-Oriented Design and Implement with Rails3
Wen-Tien Chang
 

Similar to Lecture #5 Introduction to rails (20)

Aspose pdf
Aspose pdfAspose pdf
Aspose pdf
 
Jasig rubyon rails
Jasig rubyon railsJasig rubyon rails
Jasig rubyon rails
 
Jasig rubyon rails
Jasig rubyon railsJasig rubyon rails
Jasig rubyon rails
 
Ruby Rails Web Development
Ruby Rails Web DevelopmentRuby Rails Web Development
Ruby Rails Web Development
 
Rails Concept
Rails ConceptRails Concept
Rails Concept
 
Ruby On Rails
Ruby On RailsRuby On Rails
Ruby On Rails
 
Ruby on Rails
Ruby on RailsRuby on Rails
Ruby on Rails
 
Frameworks Galore: A Pragmatic Review
Frameworks Galore: A Pragmatic ReviewFrameworks Galore: A Pragmatic Review
Frameworks Galore: A Pragmatic Review
 
Rails interview questions
Rails interview questionsRails interview questions
Rails interview questions
 
RubyonRails
RubyonRailsRubyonRails
RubyonRails
 
Ruby Rails Web Development.pdf
Ruby Rails Web Development.pdfRuby Rails Web Development.pdf
Ruby Rails Web Development.pdf
 
A Tour of Ruby On Rails
A Tour of Ruby On RailsA Tour of Ruby On Rails
A Tour of Ruby On Rails
 
Rails
RailsRails
Rails
 
Service-Oriented Design and Implement with Rails3
Service-Oriented Design and Implement with Rails3Service-Oriented Design and Implement with Rails3
Service-Oriented Design and Implement with Rails3
 
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
 
Ruby On Rails - Rochester K Linux User Group
Ruby On Rails - Rochester K Linux User GroupRuby On Rails - Rochester K Linux User Group
Ruby On Rails - Rochester K Linux User Group
 
12 Introduction to Rails
12 Introduction to Rails12 Introduction to Rails
12 Introduction to Rails
 
Ruby on rails RAD
Ruby on rails RADRuby on rails RAD
Ruby on rails RAD
 

Recently uploaded

Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
Chris Hunter
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
heathfieldcps1
 

Recently uploaded (20)

SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 

Lecture #5 Introduction to rails

  • 1. Introduction to Ruby- on-Rails Evgeniy Hinyuk Ruby-developer Github Twitter
  • 2. Who am I? Photo taken: 1.07.2016 self-educated junior ruby-developer
  • 3. Now
  • 5. What is Rails? • Ruby on Rails is an extremely productive web application framework written in Ruby by David Heinemeier Hansson in 2005. • You could develop a web application at least ten times faster with Rails than you could with a typical Java framework. • An open source Ruby framework for developing database-backed web applications. • No compilation phase required. • Full-stack framework. • Convention over Configuration
  • 6. Full-stack framework. •Includes everything needed to create a database-driven web application, using the Model-View-Controller pattern. •Being a full-stack framework means all the layers are built to work seamlessly together with less code. •Requires fewer lines of code than other frameworks.
  • 7. MVC
  • 8. Convention over Configuration •Rails shuns configuration files in favor of conventions, reflection, and dynamic runtime extensions. •Your application code and your running database already contain everything that Rails needs to know! 

  • 9. Rails Strengths •Ruby •Metaprogramming •DRY •Active Record •Convention over Configuration •Scaffolding •Built-in testing •Three environments •Fun

  • 12. App directory structure • app - main app directory • bin - rails needed scripts • config - configurations for environment, routes, etc. • db - schema.db, migrations • lib - folder for code not included in main app (like your own gems) • log - log files • public - assets for public access, 404 page etc. • test(spec) - test files • tmp - place for temporary files • vendor -folder used for third-party libraries.
  • 13. Gemfile A Gemfile is a file which is used for describing gem dependencies for Ruby programs. What is Gemfile?
  • 15. Development Workflow • Use the rails command to create the basic skeleton of the application. • Create a database on the MySQL server to hold your data. • Configure the application to know where your database is located and the login credentials for it. • Create Rails Active Records (Models), because they are the business objects you'll be working with in your controllers. • Generate Migrations that simplify the creating and maintaining of database tables and columns. • Write Controller Code to put a life in your application. • Create Views to present your data through User Interface. us start with creating our library application.
  • 17. ActiveRecord • Rails Active Record is the Object/Relational Mapping (ORM) layer supplied with Rails. • Each Active Record object has CRUD methods for database access
  • 18. Associations Active Record supports three types of associations: • One-to-one (has_one); • One-to-many (has_many); • Many-to-many (has_and_belongs_to_many, polymorphic);
  • 19. Model in DB • Each entity (such as book) gets a table in the database named after it, but in the plural (books). •  Each such entity-matching table has a field called id, which contains a unique integer for each record inserted into the table. • Given entity x and entity y, if entity y belongs to entity x, then table y has a field called x_id. • The bulk of the fields in any table store the values for that entity's simple properties (anything that's a number or a string).
  • 20. Validations The implementation of validations is done in a Rails model. The data you are entering into the database is defined in the actual Rails model, so it only makes sense to define what valid data entails in the same location. Also you can provide custom validations.
  • 21. Migrations Rails Migration allows you to use Ruby to define changes to your database schema, making it possible to use a version control system to keep things synchronized with the actual code.
  • 23. Routes The routing module provides URL rewriting in native Ruby. It's a way to redirect incoming requests to controllers and actions. Best of all, Rails' Routing works with any web server. Routes are defined in: app/config/routes.rb
  • 24. ` Rails named routes starts with HTTP verb. It supports all the verbs such as: GET, POST, PUTPATCH, DELETE.
  • 25. Routes Also rails have a special route for root path. You can match any url to any action.
  • 28. Controller The Rails controller is the logical center of your application. It coordinates the interaction between the user, the views, and the model.
  • 30. CRUD
  • 31. Strong params It provides an interface for protecting attributes from end- user assignment. This makes Action Controller parameters forbidden to be used in Active Model mass assignment until they have been whitelisted.
  • 32. Action View In Rails, web requests are handled by Action Controller and Action View. Typically, Action Controller is concerned with communicating with the database and performing CRUD actions where necessary. Action View is then responsible for compiling the response. Action View templates are written using embedded Ruby in tags mingled with HTML.
  • 34. Helpers The Rails framework provides a large number of helpers for working with assets, dates, forms, numbers and model objects, to name a few. These helpers are available to all templates by default. In addition to using the standard template helpers provided, creating custom helpers to extract complicated logic or reusable functionality is strongly encouraged.
  • 35. Rails advanced A lot of USEFULL gems
  • 36. Testing How we test rails app • Unit tests • Functional tests • Integration tests • Rspec • Factory Girl • Cucumber • Capybara • Minitest …
  • 37. Books 1. Ruby on Rails tutorial 2. Well-Grounded Rubyist 3. Rails 4 Way
  • 38. Conclusion •Rails is good for prototyping and quick development •Rails is fun! •Rails is full-stack framework based on ruby
  • 39. Thank you for your listening
  • 41. Homework Write a simple web app which allows you to create an event(bbq, pizza-day, or etc.). Add credentials to it (place, date, etc…). Add two roles, admin, and attendee. Admin can add an event, delete event, add a description, edit an event, add comments to the event. The attendee can join an event, can leave an event, can add comments to the event. You will need to cover it by your preferred test framework and deploy to Heroku.