0

I was able to setup friendly_id with one of my models (categories), but I need help with setting up with another model.

Basically I want the URL's to be something like this: domain.com/129121/title-of-post where 129121 is the ID of the post.

I tried doing this by updating the to_param but it did not work (https://github.com/gitlabhq/gitlabhq/issues/7265).

Im not sure how to get SO style links working. Any help would be appreciated!

nahtnam
  • 2,659
  • 1
  • 18
  • 31

1 Answers1

0

I tried something similar and come up with

 def slug
  name.downcase.gsub(" ", "-")  # you can change name to the attribute that holds your title
 end

 def to_param
  "#{self.id}-#{slug}"
end

Might get you on your way

Richlewis
  • 15,070
  • 37
  • 122
  • 283
  • I actually wanted a `/` to separate the id and the name. (Look at the URL of stack overflow. I want something like that.) – nahtnam Oct 01 '14 at 14:45
  • there was a reason why i didnt go that far, complications with routes and performance, ill dig out the reasons and let you know – Richlewis Oct 01 '14 at 14:56
  • Ok. Thanks. I knew how to use to_param, but I wanted them to look exactly like SO's since they look cool. – nahtnam Oct 02 '14 at 00:29