omninonsense
omninonsense

Reputation: 6882

How to shorten a single resourceful Rails route?

So, I have the following in routes.rb:

scope(path_names: { new: "register" }) do
  resources :accounts
end

This works, as it generates a /accounts/register route, but would like to change it to simply say /register. I know I could use match "/register" => "accounts#new", but I am wondering if there is a better way to accomplish this, as this would still leave the /accounts/register route "open". I could probably rename it to something obscure by using {new: "pygmy_puff"}, but I am not confident if it's the right approach.

I'd really like to do this right.

Thanks

Upvotes: 1

Views: 266

Answers (2)

Substantial
Substantial

Reputation: 6682

Try this:

match "/register" => "accounts#new"
# ...
 scope(path_names: { new: "register" }) do
  resources :accounts, :except => :new
end

In that order.

Upvotes: 1

DGM
DGM

Reputation: 26979

Personally, I wouldn't sweat the extra route, and use the extra match statement. Looking forward to rails 4, though I think it would be better written with the http method:

get "/register" => "accounts#new"

Upvotes: 1

Related Questions