rails advantages and techniques

48
Rails advantages and techniques

Upload: defv

Post on 19-Jan-2015

5.827 views

Category:

Business


2 download

DESCRIPTION

Introduction to rails, and much used techniques, I presented at barcampbrussels

TRANSCRIPT

Page 1: Rails advantages and techniques

Rails advantages and techniques

Page 2: Rails advantages and techniques

Person.find_by_name ‘Jan’

Page 3: Rails advantages and techniques

• Jan ‘DefV’ De Poorter

• Developer, IT Engineer

• Openminds, #1 Rails Hoster in .be

• blog.defv.be

• Trying to be first on google as Jan

Page 4: Rails advantages and techniques

Ruby on Rails

Page 5: Rails advantages and techniques

Ruby on Railsit does scale

Page 6: Rails advantages and techniques

• Framework based on Ruby

• Fast, agile development

• www.rubyonrails.com

Page 7: Rails advantages and techniques

So... Why ?“I already know PHP/.NET/...”

Page 8: Rails advantages and techniques

Fast Development

Page 9: Rails advantages and techniques

• CRUD

• Scaffolding (if you really need to)

• DRY

• AJAX

• acts_as_something

Page 10: Rails advantages and techniques

Maintainable

Page 11: Rails advantages and techniques

• Very readable code

• Implemented documentation system (RDOC)

• Tests makes sure you don’t break anything

Page 12: Rails advantages and techniques

Model View Controller

Page 13: Rails advantages and techniques

• Interface to the database

• Business Logic goes here

• For the DataBase Admin

Model View Controller

class User < ActiveRecord::Basehas_many :tasks

end

class Task < ActiveRecord::Basebelongs_to :user

end

Page 14: Rails advantages and techniques

• Link between DB (model) and User (view)

• HTTP / Sessions / Cookies / Post / Get

• For the Developer

Model View Controller

class TaskController < ApplicationControllerdef index@tasks = User.find(session[:user_id]).tasks

endend

Page 15: Rails advantages and techniques

• Web Interface

• What the client sees

• For the Designer

Model View Controller

...<body><% @tasks.each do |task| %><div class=’task’><%= task.content %> is <%= task.status %>

</div><% end %></body>...

Page 16: Rails advantages and techniques

Testing

Page 17: Rails advantages and techniques

Test-Driven Development

Page 18: Rails advantages and techniques

• Write tests first

Test-Driven Development

Page 19: Rails advantages and techniques

• Write tests first

• FAIL

Test-Driven Development

Page 20: Rails advantages and techniques

• Write tests first

• FAIL

• Implement

Test-Driven Development

Page 21: Rails advantages and techniques

• Write tests first

• FAIL

• Implement

•SUCCEED

Test-Driven Development

Page 22: Rails advantages and techniques

• Write tests first

• FAIL

• Implement

•SUCCEED

• Clean Up

Test-Driven Development

Page 23: Rails advantages and techniques

• Write tests first

• FAIL

• Implement

•SUCCEED

• Clean Up

• Check-In to Version Management

Test-Driven Development

Page 24: Rails advantages and techniques

that seems more work?

Page 25: Rails advantages and techniques

no

Page 26: Rails advantages and techniques

no (but..)

Page 27: Rails advantages and techniques

• No, because

• No more broken builds

• Fix bugs forever

• Think before you implement

• Small steps

• Yes, because

• it takes time to learn

Page 28: Rails advantages and techniques

Not only for developers!

Page 29: Rails advantages and techniques

def test_if_layout_elements_are_presentassert_select “body” doassert_select “div.task”, :count => 3 doassert_select “ul” doassert_select “li”, :count => 3

endend

endend

Page 30: Rails advantages and techniques

is that all ?

Page 31: Rails advantages and techniques

No!

Page 32: Rails advantages and techniques

No!

polymorphism

Page 33: Rails advantages and techniques

No!

polymorphism20.minutes.ago

Page 34: Rails advantages and techniques

No!

polymorphism20.minutes.ago

1.gigabyte

Page 35: Rails advantages and techniques

No!

polymorphism20.minutes.ago

1.gigabyte

time_ago_in_words

Page 36: Rails advantages and techniques

No!

polymorphism20.minutes.ago

1.gigabyte

time_ago_in_words

prototype

Page 37: Rails advantages and techniques

No!

polymorphism20.minutes.ago

1.gigabyte

time_ago_in_words

prototype

has_and_belongs_to_many

Page 38: Rails advantages and techniques

No!

polymorphism20.minutes.ago

1.gigabyte

time_ago_in_words

prototype

has_and_belongs_to_many

cache

Page 39: Rails advantages and techniques

No!

polymorphism20.minutes.ago

1.gigabyte

time_ago_in_words

prototype

has_and_belongs_to_many

cache

routes

Page 40: Rails advantages and techniques

No!

polymorphism20.minutes.ago

1.gigabyte

time_ago_in_words

prototype

has_and_belongs_to_many

cache

routes

link_to_remote

Page 41: Rails advantages and techniques

No!

polymorphism20.minutes.ago

1.gigabyte

time_ago_in_words

prototype

has_and_belongs_to_many

cache

routes

link_to_remote

<%= debug object %>

Page 42: Rails advantages and techniques

No!

polymorphism20.minutes.ago

1.gigabyte

time_ago_in_words

prototype

has_and_belongs_to_many

cache

routes

link_to_remote

<%= debug object %>

delegate

Page 43: Rails advantages and techniques

No!

polymorphism20.minutes.ago

1.gigabyte

time_ago_in_words

prototype

has_and_belongs_to_many

cache

routes

link_to_remote

<%= debug object %>

group_by

delegate

Page 44: Rails advantages and techniques

No!

polymorphism20.minutes.ago

1.gigabyte

time_ago_in_words

prototype

has_and_belongs_to_many

cache

routes

link_to_remote

<%= debug object %>

group_by

find_by_sql

delegate

Page 45: Rails advantages and techniques

No!

polymorphism20.minutes.ago

1.gigabyte

time_ago_in_words

prototype

has_and_belongs_to_many

cache

routes

link_to_remote

<%= debug object %>

group_by

find_by_sql

REST

delegate

Page 46: Rails advantages and techniques

No!

polymorphism20.minutes.ago

1.gigabyte

time_ago_in_words

prototype

has_and_belongs_to_many

cache

routes

link_to_remote

<%= debug object %>

group_by

find_by_sql

REST

titleize

delegate

Page 47: Rails advantages and techniques

No!

polymorphism20.minutes.ago

1.gigabyte

time_ago_in_words

prototype

has_and_belongs_to_many

cache

routes

link_to_remote

<%= debug object %>

group_by

find_by_sql

REST

titleize

...

delegate

Page 48: Rails advantages and techniques

Q & AExamples?Discussion

Thank you for listeningJan De Poorter - Openminds