map.connect syntax for rails 3
I started learning rails a few days ago and I'm reading head first rails (Dont judge, we all have to start somewhere). It seems to be using rails 2.3 whereas I'm using 3.0....
My question is syntactical.
Routing used to be done with
#map.connect 'ads/:id', :controller=>'ads', :action=>'show'
开发者_如何学C
My new attempt at it is this
match "ads/id" => "ads" :action "show"
or
match "ads/id" => "ads" "show"
Both of which give me errors. For the first one, :action gives me unexpected kend and points to the 'a'.
without it i get missing action.
Can anyone help me out with the correct syntax?
Here's the format you want to use:
match "/ads/:id" => "ads#show"
The official Rails Routing from the Outside In guide is a great resource to learn about routes.
This worked for me
match '/ads/:id' => 'ads#show'
You could switch to using RESTful routes. This means simply using
resources :ads
Which automatically matches ads/:id
to the show
action of the Ads
controller, as well as the 6 other actions. If you only want to enable the show
action, you can use:
resources :ads, :only => :show
精彩评论