使用友好_id宝石时 - 您可以忽略某些路线,例如 /about /toction吗?

发布于 2025-01-27 07:49:44 字数 563 浏览 3 评论 0原文

我正在使用Rails应用程序中使用Friendly_id Gem,以便能够在site.com/ormanisation-name上查看组织

。友好的_id假设这些页面应指向记录,因此我会遇到此错误。

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'

是否可以完全忽略这些路线,还是我需要用其他东西前缀?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

把昨日还给我 2025-02-03 07:49:44

解决方案是简单地重新排序我的路线,以将静态页面路由放在我的组织路线上的定义上: -

  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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文