Reputation: 1479
In ruby on rails when I run 'rake routes' the output for example is
Prefix Verb URI Pattern Controller#Action
users GET /users(.:format) users#index
POST /users(.:format) users#create
what does the (.:format) mean?
Upvotes: 1
Views: 252
Reputation: 12397
:format
) defines a variable, which can be accessed later in your controller via the params
hash.Depending on your controller, your users can be retrieved in multiple formats in this particular example (e.g. /users.json
and /users.xml
). When the format variable is omitted (e.g. accessing /users
), Rails defaults to the HTML format.
Be sure to check the offical Rails Guides and especially the sections 3.1 Bound Parameters and 3.2 Dynamic Segments for more information.
Upvotes: 2
Reputation: 1144
The format refers the the data format being requested. This might be JSON or XML, so your route would match:
/users.json or /users.xml
Leaving this blank, gives the HTML version.
Upvotes: 1