lundi 19 octobre 2015

Modifying route names - rails

I have 2 models (Book and Review) and 2 controllers(Books and Reviews). A book has many Reviews and Reviews belong to a Book.

Routes: resources :books

In the show controller i have:

@book = Book.find(params[:id])
@reviews = @book.review

1) This results in a route of:

https://localhost:8080/books/1

I want this to be:

https://localhost:8080/harry_potter/reviews

where name of the book = Harry Potter

2) And when i set up the reviews page i want the route to be:

https://localhost:8080/harry_potter/reviews/new_york_times

instead of

https://localhost:8080/reviews/1

where name of reviewer = New York Times

Aucun commentaire:

Enregistrer un commentaire