Reputation: 3
I use this tutorial as the base (Railscasts - Model name in url, 5:30) https://www.youtube.com/watch?v=963wTp9FCn4
I've added:
resources :points, path: "", only: [:show]
and now I can access the page by /page-name
only when I access it directly. When point_path(point)
or just point
is used in one of my views it takes me to the same /points/page-name
. So in Rails 4 I also have to modify my resourceful URL helpers?
edit: rake routes:
Prefix Verb URI Pattern Controller#Action
import_points POST /points/import(.:format) points#import
points GET /points(.:format) points#index
POST /points(.:format) points#create
new_point GET /points/new(.:format) points#new
edit_point GET /points/:id/edit(.:format) points#edit
point GET /points/:id(.:format) points#show
PATCH /points/:id(.:format) points#update
PUT /points/:id(.:format) points#update
DELETE /points/:id(.:format) points#destroy
root GET / static_pages#home
contact GET /contact(.:format) static_pages#contact
portfolio GET /portfolio(.:format) static_pages#portfolio
about GET /about(.:format) static_pages#about
login GET /login(.:format) sessions#new
POST /login(.:format) sessions#create
logout GET /logout(.:format) sessions#destroy
test GET /test(.:format) static_pages#test
GET /:id(.:format) points#show
edit2:
I have checked resources :points, path: "", only: [:show]
route on another ROR installation and it works, with IDs.
I am using friendly_id gem and the route matches :id instead of my slugged name.
edit3: If I create slugs "manually" like in tutorial everything's working like intended.
edit4: if I put resources :points, path: "", only: [:show]
on the top of the routes file point
helper gives me right paths, but my static routes are broken.
Thanks in advance!
Upvotes: 0
Views: 1074
Reputation: 36880
resources :points, path: "", as: 'direct_points', only: [:show]
This will give you
direct_point_path(point)
Which is what you want... it will resolve to (application)/(page_name)
Upvotes: 1