21
Relearning routes in Rails Routes in Rails 3 Juliana M. de Lucena @julianalucenaa (Yes, it has two ‘a’)

Relearning routes in Rails

Embed Size (px)

Citation preview

Relearning routes in Rails

Routes in Rails 3

Juliana M. de Lucena@julianalucenaa

(Yes, it has two ‘a’)

“I love URLs. I dream about them at night. I think about them before I think about anything else.”

Adrian Holovaty, co-creator of DjangoFrom Webstock 2009

What have changed?

Everything

(From version 2 to 3)

Almost

Our Path

• Good perceptions• Block declaration• Let’s see some routes

– Root– Resource– Default– Using constraints– Redirect– Namespace on route– Translating

• Let’s MAKE some routes

Good Perceptions

• Concise

• Clean

• Fast

• In a Rubyish-way

Block Declaration

Old one

New one

You do not need to use map anymore

Let’s see some routing

• Root route

Old one

New one

Concise

Let’s see some routing

• Resource route

– Nested resources

Old one

New one

Clean

“Resources should never be nested more than 1 level deep.” Rails Guides

Let’s see some routing

• Resource route

– Adding some routes

Old one

New one or

Rubyish

Let’s see some routing

• Default route

Old one

New one

And you can name it like below

It generates show_tag_type_path

Tired of showing Rails 2 examples

Sorry

Let’s move on without them

Let’s see some routing

• Using constraints

– On HTTP method

– On some fragment

Let’s see some routing

• Redirect route

• Namespace on route

Admin::LibrariesController

Let’s see some routing

• Translating routes (it can be useful for us?)

Enough! <O>Let’s MAKE some routing

You can see more surfing through the web

Let’s MAKE some routing

• Some advises

– In a DOJO way

– We are interest just on routes, forget about view, models and controllers things

– Do not be scared with specification, it will be very simple

Control your anxiety, it is on next page

Let’s MAKE some routing

• Exists a library– That has many books, employees and students

• A book– Can be created, edited, updated, deleted by any

employee

– Can be seen, borrowed and returned by everyone

– Is identified by a five characters code

• All employees– Can access some library private informations through

a special URL that begins with ‘admin’

Post method

Let’s MAKE some routing

• The library changed the name:

– When somebody access /my_old_library should redirect to /my_new_library

• With ‘/library/branchs’ we can see all libraries physical addresses (static page)

• Do not forget the root path

• All routes should be translated to portuguese

Thank you all

See u later

Juliana M. de Lucena@julianalucenaa

(Yes, it has two ‘a’)