Chapter 2 - Routing Flashcards

1
Q

The two Purposes of routing

A
  • Recognizing incoming requests and mapping them to a corresponding controller action, along with any additional variable receptors
  • Recognizing URL parameters in methods such as link_to and matching them up to a corresponding route so that proper HTML links can be generated
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

The two Purposes of routing

A

It maps requests to controller action methods, and it enables the dynamic generation of URLs for you for use as arguments to methods like link_to and redirect_to.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

REST

A

representational state transfer (REST).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Regular Routes

A

get ‘products/: id’ = > ‘products# show’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Constraining Request Methods

A

As of Rails 4, it’s recommended to limit the HTTP method used to access a route. If you are using the match directive to define a route, you accomplish this by using the :via option:

match ‘products/: id’ = > ‘products# show’, via: :get

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

segment keys

A

The URL pattern string can contain parameters (denoted with a colon), referred to as segment keys. In the following route declaration, :id is a segment key:

get ‘products/: id’ = > ‘products# show’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Redirect method

A

get “/ foo”, to: redirect(‘/ bar’)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Route Globbing

A

In some situations, you might want to grab one or more components of a route without having to match them one by one to specific positional parameters.

You define it by globbing the route with an asterisk.

get ‘items/ list/* specs’, controller: ‘items’, action: ‘list’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Create Named Route

A

get ‘help’ = > ‘help# index’, as: ‘help’

In this example, Rails will generate methods called help_url and help_path in controller and view contexts, which you can use wherever Rails expects a URL or URL components:

link_to “Help”, help_path

And, of course, the usual recognition and generation rules are in effect. The pattern string consists of just the static string component “help”. Therefore, the path you’ll see in the hyperlink will be the following:

/help

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Create Named Route

A

get ‘help’ = > ‘help# index’, as: ‘help’

In this example, Rails will generate methods called help_url and help_path in controller and view contexts, which you can use wherever Rails expects a URL or URL components:

link_to “Help”, help_path

And, of course, the usual recognition and generation rules are in effect. The pattern string consists of just the static string component “help”. Therefore, the path you’ll see in the hyperlink will be the following:

/help

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

name_path vs name_url

A

> > app.clients_path = > “/ clients”

> > app.clients_url = > “http:// www.example.com/ clients”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Namespaces

A
namespace :auctions, :controller = > :auctions do
   get 'new' = > :new 
   get 'edit/: id' = > :edit
   post 'pause/: id' = > :pause 
end
How well did you know this?
1
Not at all
2
3
4
5
Perfectly