Gerwood
Gerwood

Reputation: 5

Removing resource name from rails urls

I have an app that I want to have reflect a similar url style to that of github:

/:user/:project

I can do this directly through match but this pretty much undoes the usefulness of resources routing. Does anyone know of a good way to get rails to use the above style of url for certain resources without having to hack up every path?

I've looked at some of the slug stuff but this seems to leave the '/users/' part of the path in which is what I want to remove.

Thanks

Upvotes: 0

Views: 827

Answers (1)

danigb
danigb

Reputation: 831

What I use:

resources :users, :path => '' do
  resources :projects, :path => ''
end

And override to_param method of User and Project, for example:

class User
  def to_param
    name.parameterize
  end
end

Upvotes: 2

Related Questions