rails advantages and techniques

Post on 19-Jan-2015

5.833 Views

Category:

Business

2 Downloads

Preview:

Click to see full reader

DESCRIPTION

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

TRANSCRIPT

Rails advantages and techniques

Person.find_by_name ‘Jan’

• Jan ‘DefV’ De Poorter

• Developer, IT Engineer

• Openminds, #1 Rails Hoster in .be

• blog.defv.be

• Trying to be first on google as Jan

Ruby on Rails

Ruby on Railsit does scale

• Framework based on Ruby

• Fast, agile development

• www.rubyonrails.com

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

Fast Development

• CRUD

• Scaffolding (if you really need to)

• DRY

• AJAX

• acts_as_something

Maintainable

• Very readable code

• Implemented documentation system (RDOC)

• Tests makes sure you don’t break anything

Model View Controller

• 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

• 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

• 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>...

Testing

Test-Driven Development

• Write tests first

Test-Driven Development

• Write tests first

• FAIL

Test-Driven Development

• Write tests first

• FAIL

• Implement

Test-Driven Development

• Write tests first

• FAIL

• Implement

•SUCCEED

Test-Driven Development

• Write tests first

• FAIL

• Implement

•SUCCEED

• Clean Up

Test-Driven Development

• Write tests first

• FAIL

• Implement

•SUCCEED

• Clean Up

• Check-In to Version Management

Test-Driven Development

that seems more work?

no

no (but..)

• No, because

• No more broken builds

• Fix bugs forever

• Think before you implement

• Small steps

• Yes, because

• it takes time to learn

Not only for developers!

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

is that all ?

No!

No!

polymorphism

No!

polymorphism20.minutes.ago

No!

polymorphism20.minutes.ago

1.gigabyte

No!

polymorphism20.minutes.ago

1.gigabyte

time_ago_in_words

No!

polymorphism20.minutes.ago

1.gigabyte

time_ago_in_words

prototype

No!

polymorphism20.minutes.ago

1.gigabyte

time_ago_in_words

prototype

has_and_belongs_to_many

No!

polymorphism20.minutes.ago

1.gigabyte

time_ago_in_words

prototype

has_and_belongs_to_many

cache

No!

polymorphism20.minutes.ago

1.gigabyte

time_ago_in_words

prototype

has_and_belongs_to_many

cache

routes

No!

polymorphism20.minutes.ago

1.gigabyte

time_ago_in_words

prototype

has_and_belongs_to_many

cache

routes

link_to_remote

No!

polymorphism20.minutes.ago

1.gigabyte

time_ago_in_words

prototype

has_and_belongs_to_many

cache

routes

link_to_remote

<%= debug object %>

No!

polymorphism20.minutes.ago

1.gigabyte

time_ago_in_words

prototype

has_and_belongs_to_many

cache

routes

link_to_remote

<%= debug object %>

delegate

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

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

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

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

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

Q & AExamples?Discussion

Thank you for listeningJan De Poorter - Openminds

top related