When using the friendly_id gem - can you ignore certain routes like /about /contact?

56 Views Asked by At

I'm using the friendly_id gem in a Rails application, to be able to view organisations at site.com/organisation-name

The problem is that I have a few static pages like "About" and "Contact" at site.com/about and friendly_id assumes these pages should point to a record, hence I get this error.

ActiveRecord::RecordNotFound in OrganisationsController#show
can't find record with friendly id: "about"

routes.rb

  resources :organisations, path: "", except: [:index, :new, :create] do
    resources :posts
  end
  get '/organise', to: 'home#organise'
  get '/privacy', to: 'home#privacy'
  get '/about', to: 'home#about'
  get '/terms', to: 'home#terms'

Is there a way to ignore these routes at all, or do I need to prefix them with something else?

1

There are 1 best solutions below

0
s89_ On BEST ANSWER

The solution was to simply reorder my routes to put the static page routes above my organisations route definition:-

  get '/organise', to: 'home#organise'
  get '/privacy', to: 'home#privacy'
  get '/about', to: 'home#about'
  get '/terms', to: 'home#terms'

  resources :organisations, path: "", except: [:index, :new, :create] do
    resources :posts
  end