s89_
s89_

Reputation: 1733

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

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?

Upvotes: 1

Views: 64

Answers (1)

s89_
s89_

Reputation: 1733

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

Upvotes: 0

Related Questions