Top Banner
Relearning routes in Rails Routes in Rails 3 Juliana M. de Lucena @julianalucenaa (Yes, it has two ‘a’)
21
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Relearning routes in Rails

Relearning routes in Rails

Routes in Rails 3

Juliana M. de Lucena@julianalucenaa

(Yes, it has two ‘a’)

Page 2: Relearning routes in Rails

“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

Page 3: Relearning routes in Rails

What have changed?

Everything

(From version 2 to 3)

Almost

Page 4: Relearning routes in Rails

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

Page 5: Relearning routes in Rails

Good Perceptions

• Concise

• Clean

• Fast

• In a Rubyish-way

Page 6: Relearning routes in Rails

Block Declaration

Old one

New one

You do not need to use map anymore

Page 7: Relearning routes in Rails

Let’s see some routing

• Root route

Old one

New one

Concise

Page 8: Relearning routes in Rails

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

Page 9: Relearning routes in Rails

Let’s see some routing

• Resource route

– Adding some routes

Old one

New one or

Rubyish

Page 10: Relearning routes in Rails

Let’s see some routing

• Default route

Old one

New one

And you can name it like below

It generates show_tag_type_path

Page 11: Relearning routes in Rails

Tired of showing Rails 2 examples

Sorry

Let’s move on without them

Page 12: Relearning routes in Rails

Let’s see some routing

• Using constraints

– On HTTP method

– On some fragment

Page 13: Relearning routes in Rails

Let’s see some routing

• Redirect route

• Namespace on route

Admin::LibrariesController

Page 14: Relearning routes in Rails

Let’s see some routing

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

Page 15: Relearning routes in Rails

Enough! <O>Let’s MAKE some routing

You can see more surfing through the web

Page 16: Relearning routes in Rails

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

Page 17: Relearning routes in Rails

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

Page 18: Relearning routes in Rails

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

Page 19: Relearning routes in Rails

Thank you all

See u later

Page 21: Relearning routes in Rails

Juliana M. de Lucena@julianalucenaa

(Yes, it has two ‘a’)