30
Chapter 3.1 – RoR: An introduction Maciej Mensfeld Presented by: Maciej Mensfeld RoR: An introduction [email protected] dev.mensfeld.pl github.com/mensfeld senior ruby [email protected] senior ruby [email protected]

Chapter 3.1 – RoR: An introduction Maciej Mensfeld Presented by: Maciej Mensfeld RoR: An introduction [email protected] dev.mensfeld.pl github.com/mensfeld

Embed Size (px)

Citation preview

Page 1: Chapter 3.1 – RoR: An introduction Maciej Mensfeld Presented by: Maciej Mensfeld RoR: An introduction maciej@mensfeld.pl dev.mensfeld.pl github.com/mensfeld

Chapter 3.1 – RoR: An introduction

Maciej Mensfeld

Presented by:

Maciej Mensfeld

RoR: An introduction

[email protected]

github.com/mensfeld

senior ruby [email protected] ruby [email protected]

Page 2: Chapter 3.1 – RoR: An introduction Maciej Mensfeld Presented by: Maciej Mensfeld RoR: An introduction maciej@mensfeld.pl dev.mensfeld.pl github.com/mensfeld

Ruby on Rails: An introduction - Rules

Maciej Mensfeld

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

Page 3: Chapter 3.1 – RoR: An introduction Maciej Mensfeld Presented by: Maciej Mensfeld RoR: An introduction maciej@mensfeld.pl dev.mensfeld.pl github.com/mensfeld

Ruby on Rails: An introduction – Rails what?

Maciej Mensfeld

RoR: An introduction

Page 4: Chapter 3.1 – RoR: An introduction Maciej Mensfeld Presented by: Maciej Mensfeld RoR: An introduction maciej@mensfeld.pl dev.mensfeld.pl github.com/mensfeld

Ruby on Rails: An introduction – What is Ruby on Rails?

Maciej Mensfeld

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!

Page 5: Chapter 3.1 – RoR: An introduction Maciej Mensfeld Presented by: Maciej Mensfeld RoR: An introduction maciej@mensfeld.pl dev.mensfeld.pl github.com/mensfeld

Ruby on Rails: An introduction – What is Ruby on Rails?

Maciej Mensfeld

RoR: Why Ruby on Rails? Lot of frameworks exists on the market and a lot of

programming languages for the web but…

Rails leads

Page 6: Chapter 3.1 – RoR: An introduction Maciej Mensfeld Presented by: Maciej Mensfeld RoR: An introduction maciej@mensfeld.pl dev.mensfeld.pl github.com/mensfeld

Ruby on Rails: An introduction – What is Ruby on Rails?

Maciej Mensfeld

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

Page 7: Chapter 3.1 – RoR: An introduction Maciej Mensfeld Presented by: Maciej Mensfeld RoR: An introduction maciej@mensfeld.pl dev.mensfeld.pl github.com/mensfeld

Ruby on Rails: An introduction – What is Ruby on Rails?

Maciej Mensfeld

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

Page 8: Chapter 3.1 – RoR: An introduction Maciej Mensfeld Presented by: Maciej Mensfeld RoR: An introduction maciej@mensfeld.pl dev.mensfeld.pl github.com/mensfeld

Ruby on Rails: An introduction – Who uses RoR?

Maciej Mensfeld

I do! ;) (but not only…)

and thousands of other…

Page 9: Chapter 3.1 – RoR: An introduction Maciej Mensfeld Presented by: Maciej Mensfeld RoR: An introduction maciej@mensfeld.pl dev.mensfeld.pl github.com/mensfeld

Ruby on Rails: An introduction – The framework

Maciej Mensfeld

Lil bit bout Rails structure

The Framework

Page 10: Chapter 3.1 – RoR: An introduction Maciej Mensfeld Presented by: Maciej Mensfeld RoR: An introduction maciej@mensfeld.pl dev.mensfeld.pl github.com/mensfeld

Ruby on Rails: An introduction – The framework

Maciej Mensfeld

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?!

Page 11: Chapter 3.1 – RoR: An introduction Maciej Mensfeld Presented by: Maciej Mensfeld RoR: An introduction maciej@mensfeld.pl dev.mensfeld.pl github.com/mensfeld

Ruby on Rails: An introduction – The framework

Maciej Mensfeld

Lil bit bout Rails structure

Fortunately you don’t need to care about this :)

Page 12: Chapter 3.1 – RoR: An introduction Maciej Mensfeld Presented by: Maciej Mensfeld RoR: An introduction maciej@mensfeld.pl dev.mensfeld.pl github.com/mensfeld

Ruby on Rails: An introduction – The framework

Maciej Mensfeld

MVC

Page 13: Chapter 3.1 – RoR: An introduction Maciej Mensfeld Presented by: Maciej Mensfeld RoR: An introduction maciej@mensfeld.pl dev.mensfeld.pl github.com/mensfeld

Ruby on Rails: An introduction – The framework

Maciej Mensfeld

Rails MVC

Page 14: Chapter 3.1 – RoR: An introduction Maciej Mensfeld Presented by: Maciej Mensfeld RoR: An introduction maciej@mensfeld.pl dev.mensfeld.pl github.com/mensfeld

Ruby on Rails: An introduction – The framework

Maciej Mensfeld

Models ;)

Page 15: Chapter 3.1 – RoR: An introduction Maciej Mensfeld Presented by: Maciej Mensfeld RoR: An introduction maciej@mensfeld.pl dev.mensfeld.pl github.com/mensfeld

Ruby on Rails: An introduction – The framework

Maciej Mensfeld

ActiveRecord models

Page 16: Chapter 3.1 – RoR: An introduction Maciej Mensfeld Presented by: Maciej Mensfeld RoR: An introduction maciej@mensfeld.pl dev.mensfeld.pl github.com/mensfeld

Ruby on Rails: An introduction – The framework

Maciej Mensfeld

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

Page 17: Chapter 3.1 – RoR: An introduction Maciej Mensfeld Presented by: Maciej Mensfeld RoR: An introduction maciej@mensfeld.pl dev.mensfeld.pl github.com/mensfeld

Ruby on Rails: An introduction – The framework

Maciej Mensfeld

But… don’t piss off Vegeta ;)

Make fat models and thin controllers or Vegeta will

visit U…

Page 18: Chapter 3.1 – RoR: An introduction Maciej Mensfeld Presented by: Maciej Mensfeld RoR: An introduction maciej@mensfeld.pl dev.mensfeld.pl github.com/mensfeld

Ruby on Rails: An introduction – The framework

Maciej Mensfeld

ActionController

Page 19: Chapter 3.1 – RoR: An introduction Maciej Mensfeld Presented by: Maciej Mensfeld RoR: An introduction maciej@mensfeld.pl dev.mensfeld.pl github.com/mensfeld

Ruby on Rails: An introduction – The framework

Maciej Mensfeld

ActionController – be Restful

Page 20: Chapter 3.1 – RoR: An introduction Maciej Mensfeld Presented by: Maciej Mensfeld RoR: An introduction maciej@mensfeld.pl dev.mensfeld.pl github.com/mensfeld

Ruby on Rails: An introduction – The framework

Maciej Mensfeld

ActionController – be Restful

Page 21: Chapter 3.1 – RoR: An introduction Maciej Mensfeld Presented by: Maciej Mensfeld RoR: An introduction maciej@mensfeld.pl dev.mensfeld.pl github.com/mensfeld

Ruby on Rails: An introduction – The framework

Maciej Mensfeld

ActionView

Page 22: Chapter 3.1 – RoR: An introduction Maciej Mensfeld Presented by: Maciej Mensfeld RoR: An introduction maciej@mensfeld.pl dev.mensfeld.pl github.com/mensfeld

Ruby on Rails: An introduction – The framework

Maciej Mensfeld

ActionView templates

ERB – templates with HTM and Ruby code – used to

display dinamic stuff from prepared by controllers

Page 23: Chapter 3.1 – RoR: An introduction Maciej Mensfeld Presented by: Maciej Mensfeld RoR: An introduction maciej@mensfeld.pl dev.mensfeld.pl github.com/mensfeld

Ruby on Rails: An introduction – Example app

Maciej Mensfeld

Enough theory, let’s start the magic!

Page 24: Chapter 3.1 – RoR: An introduction Maciej Mensfeld Presented by: Maciej Mensfeld RoR: An introduction maciej@mensfeld.pl dev.mensfeld.pl github.com/mensfeld

Ruby on Rails: An introduction – Example app

Maciej Mensfeld

Generate Rails scaffold…

Try it out!

Page 25: Chapter 3.1 – RoR: An introduction Maciej Mensfeld Presented by: Maciej Mensfeld RoR: An introduction maciej@mensfeld.pl dev.mensfeld.pl github.com/mensfeld

Ruby on Rails: An introduction – Example app

Maciej Mensfeld

Start rails server to check if it works

Try it out!

Go to http://localhost:3000/

Page 26: Chapter 3.1 – RoR: An introduction Maciej Mensfeld Presented by: Maciej Mensfeld RoR: An introduction maciej@mensfeld.pl dev.mensfeld.pl github.com/mensfeld

Ruby on Rails: An introduction – Example app

Maciej Mensfeld

Yay! It works!

Page 27: Chapter 3.1 – RoR: An introduction Maciej Mensfeld Presented by: Maciej Mensfeld RoR: An introduction maciej@mensfeld.pl dev.mensfeld.pl github.com/mensfeld

Ruby on Rails: An introduction – Example app

Maciej Mensfeld

Creating Posts

Try it out!

Page 28: Chapter 3.1 – RoR: An introduction Maciej Mensfeld Presented by: Maciej Mensfeld RoR: An introduction maciej@mensfeld.pl dev.mensfeld.pl github.com/mensfeld

Ruby on Rails: An introduction – Example app

Maciej Mensfeld

Creating Posts

Try it out!

Yeah it works but… we can create empty posts :( not good :(

Page 29: Chapter 3.1 – RoR: An introduction Maciej Mensfeld Presented by: Maciej Mensfeld RoR: An introduction maciej@mensfeld.pl dev.mensfeld.pl github.com/mensfeld

Ruby on Rails: An introduction – Example app

Maciej Mensfeld

Protect create/update/destroy

Try it out!

Our blog works but anyone can add, edit and remove posts… shitty :/

Page 30: Chapter 3.1 – RoR: An introduction Maciej Mensfeld Presented by: Maciej Mensfeld RoR: An introduction maciej@mensfeld.pl dev.mensfeld.pl github.com/mensfeld

Ruby: writing some cool stuff

Maciej Mensfeld

Live long and prosper!

Presented by:

Maciej Mensfeld

[email protected]

github.com/mensfeld