dimanche 20 octobre 2019

Rails Routing Clash When Rendering Static Pages

I have a routing clash. After moving all of my blog posts from /posts/:id to /:id (which is great), I now have an issue where my static pages don't contain an ID, so they aren't rendering. I don't want to have to process them through my posts controller.

Here's what I currently have in my routes.rb file:

  resources :posts, only: [:index, :create, :edit, :new, :destroy]
  get '/:id' => 'posts#show', :as => 'custom_url'
  match '/posts/:id' => redirect('/%{id}', status: 301)

But then these now don't work...

  match '/privacy' => 'static#privacy'
  match '/terms' => 'static#terms'

I have a controller called static_controller.rb which I can use if I need to. How can I jump over the /:id match.

Aucun commentaire:

Enregistrer un commentaire