SlideShare ist ein Scribd-Unternehmen logo
1 von 41
Downloaden Sie, um offline zu lesen
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.

Weitere ähnliche Inhalte

Was ist angesagt?

Azure App Configuration with .NET applications
Azure App Configuration with .NET applicationsAzure App Configuration with .NET applications
Azure App Configuration with .NET applicationsChristian 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 3Jukka 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 jvmIndicThreads
 
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 solutionMazenetsolution
 
Asp #2
Asp #2Asp #2
Asp #2Joni
 
SpringPeople Introduction to MongoDB Administration
SpringPeople Introduction to MongoDB AdministrationSpringPeople Introduction to MongoDB Administration
SpringPeople Introduction to MongoDB AdministrationSpringPeople
 
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-LeeEZTABLE
 
RESTful Web Service using Swagger
RESTful Web Service using SwaggerRESTful Web Service using Swagger
RESTful Web Service using SwaggerHong-Jhih Lin
 
Skillwise - Advanced web application development
Skillwise - Advanced web application developmentSkillwise - Advanced web application development
Skillwise - Advanced web application developmentSkillwise Group
 
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
 
Melbourne User Group OAK and MongoDB
Melbourne User Group OAK and MongoDBMelbourne User Group OAK and MongoDB
Melbourne User Group OAK and MongoDBYuval 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
 

Was ist angesagt? (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
 

Ähnlich wie 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 On Rails
Ruby On RailsRuby On Rails
Ruby On Railsiradarji
 
Frameworks Galore: A Pragmatic Review
Frameworks Galore: A Pragmatic ReviewFrameworks Galore: A Pragmatic Review
Frameworks Galore: A Pragmatic Reviewnetc2012
 
A Tour of Ruby On Rails
A Tour of Ruby On RailsA Tour of Ruby On Rails
A Tour of Ruby On RailsDavid 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 GroupJose de Leon
 
Ruby On Rails
Ruby On RailsRuby On Rails
Ruby On Railsiradarji
 

Ähnlich wie 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
 
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
 
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
 
Ruby On Rails
Ruby On RailsRuby On Rails
Ruby On Rails
 
Ruby On Rails
Ruby On RailsRuby On Rails
Ruby On Rails
 

Kürzlich hochgeladen

5 charts on South Africa as a source country for international student recrui...
5 charts on South Africa as a source country for international student recrui...5 charts on South Africa as a source country for international student recrui...
5 charts on South Africa as a source country for international student recrui...CaraSkikne1
 
DUST OF SNOW_BY ROBERT FROST_EDITED BY_ TANMOY MISHRA
DUST OF SNOW_BY ROBERT FROST_EDITED BY_ TANMOY MISHRADUST OF SNOW_BY ROBERT FROST_EDITED BY_ TANMOY MISHRA
DUST OF SNOW_BY ROBERT FROST_EDITED BY_ TANMOY MISHRATanmoy Mishra
 
Work Experience for psp3 portfolio sasha
Work Experience for psp3 portfolio sashaWork Experience for psp3 portfolio sasha
Work Experience for psp3 portfolio sashasashalaycock03
 
ARTICULAR DISC OF TEMPOROMANDIBULAR JOINT
ARTICULAR DISC OF TEMPOROMANDIBULAR JOINTARTICULAR DISC OF TEMPOROMANDIBULAR JOINT
ARTICULAR DISC OF TEMPOROMANDIBULAR JOINTDR. SNEHA NAIR
 
Vani Magazine - Quarterly Magazine of Seshadripuram Educational Trust
Vani Magazine - Quarterly Magazine of Seshadripuram Educational TrustVani Magazine - Quarterly Magazine of Seshadripuram Educational Trust
Vani Magazine - Quarterly Magazine of Seshadripuram Educational TrustSavipriya Raghavendra
 
3.21.24 The Origins of Black Power.pptx
3.21.24  The Origins of Black Power.pptx3.21.24  The Origins of Black Power.pptx
3.21.24 The Origins of Black Power.pptxmary850239
 
Clinical Pharmacy Introduction to Clinical Pharmacy, Concept of clinical pptx
Clinical Pharmacy  Introduction to Clinical Pharmacy, Concept of clinical pptxClinical Pharmacy  Introduction to Clinical Pharmacy, Concept of clinical pptx
Clinical Pharmacy Introduction to Clinical Pharmacy, Concept of clinical pptxraviapr7
 
The basics of sentences session 10pptx.pptx
The basics of sentences session 10pptx.pptxThe basics of sentences session 10pptx.pptx
The basics of sentences session 10pptx.pptxheathfieldcps1
 
Protein Structure - threading Protein modelling pptx
Protein Structure - threading Protein modelling pptxProtein Structure - threading Protein modelling pptx
Protein Structure - threading Protein modelling pptxvidhisharma994099
 
How to Make a Field read-only in Odoo 17
How to Make a Field read-only in Odoo 17How to Make a Field read-only in Odoo 17
How to Make a Field read-only in Odoo 17Celine George
 
Slides CapTechTalks Webinar March 2024 Joshua Sinai.pptx
Slides CapTechTalks Webinar March 2024 Joshua Sinai.pptxSlides CapTechTalks Webinar March 2024 Joshua Sinai.pptx
Slides CapTechTalks Webinar March 2024 Joshua Sinai.pptxCapitolTechU
 
Ultra structure and life cycle of Plasmodium.pptx
Ultra structure and life cycle of Plasmodium.pptxUltra structure and life cycle of Plasmodium.pptx
Ultra structure and life cycle of Plasmodium.pptxDr. Asif Anas
 
Department of Health Compounder Question ‍Solution 2022.pdf
Department of Health Compounder Question ‍Solution 2022.pdfDepartment of Health Compounder Question ‍Solution 2022.pdf
Department of Health Compounder Question ‍Solution 2022.pdfMohonDas
 
Over the counter (OTC)- Sale, rational use.pptx
Over the counter (OTC)- Sale, rational use.pptxOver the counter (OTC)- Sale, rational use.pptx
Over the counter (OTC)- Sale, rational use.pptxraviapr7
 
10 Topics For MBA Project Report [HR].pdf
10 Topics For MBA Project Report [HR].pdf10 Topics For MBA Project Report [HR].pdf
10 Topics For MBA Project Report [HR].pdfJayanti Pande
 
A gentle introduction to Artificial Intelligence
A gentle introduction to Artificial IntelligenceA gentle introduction to Artificial Intelligence
A gentle introduction to Artificial IntelligenceApostolos Syropoulos
 
EBUS5423 Data Analytics and Reporting Bl
EBUS5423 Data Analytics and Reporting BlEBUS5423 Data Analytics and Reporting Bl
EBUS5423 Data Analytics and Reporting BlDr. Bruce A. Johnson
 
Optical Fibre and It's Applications.pptx
Optical Fibre and It's Applications.pptxOptical Fibre and It's Applications.pptx
Optical Fibre and It's Applications.pptxPurva Nikam
 

Kürzlich hochgeladen (20)

5 charts on South Africa as a source country for international student recrui...
5 charts on South Africa as a source country for international student recrui...5 charts on South Africa as a source country for international student recrui...
5 charts on South Africa as a source country for international student recrui...
 
DUST OF SNOW_BY ROBERT FROST_EDITED BY_ TANMOY MISHRA
DUST OF SNOW_BY ROBERT FROST_EDITED BY_ TANMOY MISHRADUST OF SNOW_BY ROBERT FROST_EDITED BY_ TANMOY MISHRA
DUST OF SNOW_BY ROBERT FROST_EDITED BY_ TANMOY MISHRA
 
Work Experience for psp3 portfolio sasha
Work Experience for psp3 portfolio sashaWork Experience for psp3 portfolio sasha
Work Experience for psp3 portfolio sasha
 
ARTICULAR DISC OF TEMPOROMANDIBULAR JOINT
ARTICULAR DISC OF TEMPOROMANDIBULAR JOINTARTICULAR DISC OF TEMPOROMANDIBULAR JOINT
ARTICULAR DISC OF TEMPOROMANDIBULAR JOINT
 
Prelims of Kant get Marx 2.0: a general politics quiz
Prelims of Kant get Marx 2.0: a general politics quizPrelims of Kant get Marx 2.0: a general politics quiz
Prelims of Kant get Marx 2.0: a general politics quiz
 
Vani Magazine - Quarterly Magazine of Seshadripuram Educational Trust
Vani Magazine - Quarterly Magazine of Seshadripuram Educational TrustVani Magazine - Quarterly Magazine of Seshadripuram Educational Trust
Vani Magazine - Quarterly Magazine of Seshadripuram Educational Trust
 
3.21.24 The Origins of Black Power.pptx
3.21.24  The Origins of Black Power.pptx3.21.24  The Origins of Black Power.pptx
3.21.24 The Origins of Black Power.pptx
 
Clinical Pharmacy Introduction to Clinical Pharmacy, Concept of clinical pptx
Clinical Pharmacy  Introduction to Clinical Pharmacy, Concept of clinical pptxClinical Pharmacy  Introduction to Clinical Pharmacy, Concept of clinical pptx
Clinical Pharmacy Introduction to Clinical Pharmacy, Concept of clinical pptx
 
The basics of sentences session 10pptx.pptx
The basics of sentences session 10pptx.pptxThe basics of sentences session 10pptx.pptx
The basics of sentences session 10pptx.pptx
 
March 2024 Directors Meeting, Division of Student Affairs and Academic Support
March 2024 Directors Meeting, Division of Student Affairs and Academic SupportMarch 2024 Directors Meeting, Division of Student Affairs and Academic Support
March 2024 Directors Meeting, Division of Student Affairs and Academic Support
 
Protein Structure - threading Protein modelling pptx
Protein Structure - threading Protein modelling pptxProtein Structure - threading Protein modelling pptx
Protein Structure - threading Protein modelling pptx
 
How to Make a Field read-only in Odoo 17
How to Make a Field read-only in Odoo 17How to Make a Field read-only in Odoo 17
How to Make a Field read-only in Odoo 17
 
Slides CapTechTalks Webinar March 2024 Joshua Sinai.pptx
Slides CapTechTalks Webinar March 2024 Joshua Sinai.pptxSlides CapTechTalks Webinar March 2024 Joshua Sinai.pptx
Slides CapTechTalks Webinar March 2024 Joshua Sinai.pptx
 
Ultra structure and life cycle of Plasmodium.pptx
Ultra structure and life cycle of Plasmodium.pptxUltra structure and life cycle of Plasmodium.pptx
Ultra structure and life cycle of Plasmodium.pptx
 
Department of Health Compounder Question ‍Solution 2022.pdf
Department of Health Compounder Question ‍Solution 2022.pdfDepartment of Health Compounder Question ‍Solution 2022.pdf
Department of Health Compounder Question ‍Solution 2022.pdf
 
Over the counter (OTC)- Sale, rational use.pptx
Over the counter (OTC)- Sale, rational use.pptxOver the counter (OTC)- Sale, rational use.pptx
Over the counter (OTC)- Sale, rational use.pptx
 
10 Topics For MBA Project Report [HR].pdf
10 Topics For MBA Project Report [HR].pdf10 Topics For MBA Project Report [HR].pdf
10 Topics For MBA Project Report [HR].pdf
 
A gentle introduction to Artificial Intelligence
A gentle introduction to Artificial IntelligenceA gentle introduction to Artificial Intelligence
A gentle introduction to Artificial Intelligence
 
EBUS5423 Data Analytics and Reporting Bl
EBUS5423 Data Analytics and Reporting BlEBUS5423 Data Analytics and Reporting Bl
EBUS5423 Data Analytics and Reporting Bl
 
Optical Fibre and It's Applications.pptx
Optical Fibre and It's Applications.pptxOptical Fibre and It's Applications.pptx
Optical Fibre and It's Applications.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.