user929062
user929062

Reputation: 817

Simple way`to rename resource to make it a friendly URL?

I have

resources :articles

and in article.rb

def to_param
    "#{id}-#{name.downcase.gsub(/\s+/, "_")}"
end

So the URL will be like

www.example.com/articles/1-Name-of-the-first-article

I am now trying to find a simple solution to always substitute "article" in the URL with "encyclopedia". So the path should be

www.example.com/encyclopedia/1-Name-of-the-first-article

Is there a simple solution?

Upvotes: 0

Views: 41

Answers (1)

t56k
t56k

Reputation: 6981

Really simple.

routes.rb

resources :articles, :path => :encyclopedia

Upvotes: 1

Related Questions