Blankman
Blankman

Reputation: 267220

Rails 3 routing help, how can I use resources for this?

My account_controller has the following actions:

/accounts/index /accounts/show/12321 /accounts/edit/234234

I have this so far in my routes file:

get "accounts/index"  
match "accounts/show/:id" => "accounts#show"

Can I use resources instead somehow?

Currently my accounts#index routes doesn't work if you have a url like:

/accounts/

Upvotes: 0

Views: 21

Answers (1)

Brandan
Brandan

Reputation: 14983

Using resources would change your URL structure:

  • /accounts/index would become /accounts
  • /accounts/show/:id would become /accounts/:id
  • /accounts/edit/:id would become /accounts/:id/edit

But the action names in the controller would stay the same.

If you don't mind losing the old URLs, or if you could set up redirects from the old URLs to the new ones, then using resources would result in a more conventional, RESTful design, so it's "better" by that standard.

Upvotes: 1

Related Questions