nonopolarity
nonopolarity

Reputation: 151196

In Ruby on Rails, routes.rb, if map.something will create something_path and something_url, does map.connect create something like that too?

In Ruby on Rails, routes.rb, if we create a "named route"

map.something ":a/:b", :controller => 'foobar'

it will also create something_path and something_url which are two methods usable in the controller and in the view. Does map.connect create something like that too? Otherwise, isn't map.connect somewhat disadvantaged in this way? I checked that connect_path and connect_url both aren't created automatically.

Upvotes: 0

Views: 1317

Answers (2)

Shripad Krishna
Shripad Krishna

Reputation: 10498

A named route can be thought of as a named map.connect route. map.connect just establishes a route that points to an action within a controller. But it would be a pain to call the route again and again everywhere. Using a named route is more readable. The advantage of map.connect is that it can be made to connect to any controllers action. If you read the routes.rb file carefully you see that the following two statements have the lowest priority:

Note: These default routes make all actions in every controller accessible via GET requests. You should
consider removing or commenting them out if you're using named routes and resources.
    map.connect ':controller/:action/:id'
    map.connect ':controller/:action/:id.:format'

If you comment out the above two lines you will not be able to reach any route except for the ones that you define using named routes/resources.

Upvotes: 0

alternative
alternative

Reputation: 13042

You are correct in your thinking. map.connect does not create something_path and something_url. This is the purpose of named routes like map.something: To create "names," hence the name "named routes."

Upvotes: 1

Related Questions