Using something other than ID in routes

265 views Asked by At

I have two models, Book and Chapter.

I would like chapters to be accessed by their order in the book rather that their id's

/Books/the-chapter-title/chapters/1

Would it be recommended to do this as I would like to also have the ability to reorder the chapters.

I would like the chapter numbers to move up and down the list using acts-as-list but also access them via their pecking order.

1

There are 1 answers

2
daniel On

you can add a to_params method in your model if you want to use something other than id, but this usually leads to headaches

check out https://github.com/norman/friendly_id