Ruby on Rails: An introduction - Who am I? Maciej Mensfeld Presented by: Maciej Mensfeld RoR: An introduction [email protected] dev.mensfeld.pl github.com/mensfeld senior ruby [email protected] lead ruby [email protected]
Feb 22, 2016
Ruby on Rails: An introduction - Who am I?
Maciej Mensfeld
Presented by:
Maciej Mensfeld
RoR: An introduction
github.com/mensfeld
senior ruby [email protected] ruby [email protected]
Ruby on Rails: An introduction - Rules
Maciej Mensfeld 2/30
Please…
• …ask me to slow down, if I speak to quickly;• …ask me again, if I forget;
• …ask questions, if anything i say is not clear;• …feel free to share your own observations
RoR: An introduction
Ruby on Rails: An introduction – Rails what?
Maciej Mensfeld 3/30
RoR: An introduction
Ruby on Rails: An introduction – What is Ruby on Rails?
Maciej Mensfeld 4/30
RoR: What is Ruby on Rails?
•Full stack web application framework•Written in the Ruby programming language•Growing community since 2004•Open Source and Free•Focused on developer productivity and getting the job done – fast!
Ruby on Rails: An introduction – What is Ruby on Rails?
Maciej Mensfeld 5/30
RoR: Why Ruby on Rails? Lot of frameworks exists on the market and a lot of
programming languages for the web but…
Rails leads
Ruby on Rails: An introduction – What is Ruby on Rails?
Maciej Mensfeld 6/30
RoR: Why Ruby on Rails? •Rails give the developers a real productivity boost for developing web applications•Because of Ruby and domain specific languages•Convention over Configuration•Productivity boost!
Really faster?
3-4 times faster than
dev with zend
Ruby on Rails: An introduction – What is Ruby on Rails?
Maciej Mensfeld 7/30
RoR: Why Ruby on Rails?
Designed to make it easier to develop, deploy, and maintain web applications
Design with Model-View-ControllerAlso based on DRY concept
Don’t Repeat Yourself (DRY)Every piece of knowledge should be expressed in just one place
Ruby on Rails: An introduction – Who uses RoR?
Maciej Mensfeld 8/30
I do! ;) (but not only…)
and thousands of other…
Ruby on Rails: An introduction – The framework
Maciej Mensfeld 9/30
Lil bit bout Rails structure
The Framework
Ruby on Rails: An introduction – The framework
Maciej Mensfeld 10/30
Lil bit bout Rails structure
Try it out!
cd ~rails new my_blog…(output):create create README create Rakefile create config.ru create .gitignore create Gemfile create app create app/assets/images/rails.png…
To much stuff! WTF?!
Ruby on Rails: An introduction – The framework
Maciej Mensfeld 0
Lil bit bout Rails structure
Fortunately you don’t need to care about this :)
Ruby on Rails: An introduction – The framework
Maciej Mensfeld 12/30
MVC
Ruby on Rails: An introduction – The framework
Maciej Mensfeld 13/30
Rails MVC
Ruby on Rails: An introduction – The framework
Maciej Mensfeld 14/30
Models ;)
Ruby on Rails: An introduction – The framework
Maciej Mensfeld 15/30
ActiveRecord models
Ruby on Rails: An introduction – The framework
Maciej Mensfeld 16/30
Models should be…
Fat! Fat! Fat!!!!
Fat! Fat! Fat!!!!
Fat! Fat! Fat!!!!
Fat! Fat! Fat!!!!
Fat! Fat! Fat!!!!Fat m
odel
s, th
in c
ontr
olle
rs
Ruby on Rails: An introduction – The framework
Maciej Mensfeld 17/30
But… don’t piss off Vegeta ;)
Make fat models and thin controllers or Vegeta will
visit U…
Ruby on Rails: An introduction – The framework
Maciej Mensfeld 18/30
ActionController
Ruby on Rails: An introduction – The framework
Maciej Mensfeld 19/30
ActionController – be Restful
Ruby on Rails: An introduction – The framework
Maciej Mensfeld 20/30
ActionController – be Restful
Ruby on Rails: An introduction – The framework
Maciej Mensfeld 21/30
ActionView
Ruby on Rails: An introduction – The framework
Maciej Mensfeld 22/30
ActionView templates
ERB – templates with HTM and Ruby code – used to
display dinamic stuff from prepared by controllers
Ruby on Rails: An introduction – Example app
Maciej Mensfeld 23/30
Enough theory, let’s start the magic!
Ruby on Rails: An introduction – Example app
Maciej Mensfeld 24/30
Generate Rails scaffold…
Try it out!
Ruby on Rails: An introduction – Example app
Maciej Mensfeld 25/30
Start rails server to check if it works
Try it out!
Go to http://localhost:3000/
Ruby on Rails: An introduction – Example app
Maciej Mensfeld 26/30
Yay! It works!
Ruby on Rails: An introduction – Example app
Maciej Mensfeld 27/30
Creating Posts
Try it out!
Ruby on Rails: An introduction – Example app
Maciej Mensfeld 28/30
Creating Posts
Try it out!
Yeah it works but… we can create empty posts :( not good :(
Ruby on Rails: An introduction – Example app
Maciej Mensfeld 29/30
Protect create/update/destroy
Try it out!
Our blog works but anyone can add, edit and remove posts… shitty :/
Ruby: writing some cool stuff
Maciej Mensfeld 30/30
Live long and prosper!
Presented by:
Maciej Mensfeld
github.com/mensfeld