SlideShare a Scribd company logo
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

Azure App Configuration with .NET applications
Azure App Configuration with .NET applicationsAzure App Configuration with .NET applications
Azure App Configuration with .NET applications
Christian Nagel
 
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
Jukka Zitting
 
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
IndicThreads
 
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
Mazenetsolution
 
Asp #2
Asp #2Asp #2
Asp #2
Joni
 
Asp.net
Asp.netAsp.net
Asp.net
KIRTI PRADHAN
 
SpringPeople Introduction to MongoDB Administration
SpringPeople Introduction to MongoDB AdministrationSpringPeople Introduction to MongoDB Administration
SpringPeople Introduction to MongoDB Administration
SpringPeople
 
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)
Richard Cyganiak
 
【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
EZTABLE
 
RESTful Web Service using Swagger
RESTful Web Service using SwaggerRESTful Web Service using Swagger
RESTful Web Service using Swagger
Hong-Jhih Lin
 
Skillwise - Advanced web application development
Skillwise - Advanced web application developmentSkillwise - Advanced web application development
Skillwise - Advanced web application development
Skillwise Group
 
D2RQ
D2RQD2RQ
RavenDB Presentation
RavenDB PresentationRavenDB Presentation
RavenDB PresentationMark Rodseth
 
NoSQL Database in .NET Apps
NoSQL Database in .NET AppsNoSQL Database in .NET Apps
NoSQL Database in .NET AppsShiju Varghese
 
Scala and Lift
Scala and LiftScala and Lift
Scala and Lift
Sander Mak (@Sander_Mak)
 
Melbourne User Group OAK and MongoDB
Melbourne User Group OAK and MongoDBMelbourne User Group OAK and MongoDB
Melbourne User Group OAK and MongoDB
Yuval Ararat
 
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 ...
European Collaboration Summit
 
WCM-7 Surfing with CMIS
WCM-7 Surfing with CMISWCM-7 Surfing with CMIS
WCM-7 Surfing with CMIS
Alfresco Software
 

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

Aspose pdf
Aspose pdfAspose pdf
Aspose pdf
Jim Jones
 
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
Ruby Rails Web DevelopmentRuby Rails Web Development
Ruby Rails Web Development
Sonia Simi
 
Ruby On Rails
Ruby On RailsRuby On Rails
Ruby On Rails
iradarji
 
Ruby on Rails
Ruby on RailsRuby on Rails
Frameworks Galore: A Pragmatic Review
Frameworks Galore: A Pragmatic ReviewFrameworks Galore: A Pragmatic Review
Frameworks Galore: A Pragmatic Review
netc2012
 
Rails interview questions
Rails interview questionsRails interview questions
Rails interview questions
Durgesh Tripathi
 
Ruby Rails Web Development.pdf
Ruby Rails Web Development.pdfRuby Rails Web Development.pdf
Ruby Rails Web Development.pdf
Ayesha Siddika
 
A Tour of Ruby On Rails
A Tour of Ruby On RailsA Tour of Ruby On Rails
A Tour of Ruby On Rails
David Keener
 
Rails
RailsRails
RailsSHC
 
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 Rails3Wen-Tien Chang
 
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
Jose de Leon
 
12 Introduction to Rails
12 Introduction to Rails12 Introduction to Rails
12 Introduction to Rails
Deepak Hagadur Bheemaraju
 

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

Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
AzmatAli747758
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
EduSkills OECD
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
Fundacja Rozwoju Społeczeństwa Przedsiębiorczego
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
Excellence Foundation for South Sudan
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
Celine George
 

Recently uploaded (20)

Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
 

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.