【问题标题】:Rails 5: redirect wildcards except mentioned ones in routesRails 5:重定向通配符,除了路线中提到的通配符
【发布时间】:2023-03-30 03:29:01
【问题描述】:

我的 routes.rb 中有这个

constraints SubdomainConstraint do
  scope '/', controller: :hub_categories do
    get '/', to: 'hub_categories#index'
    get 'list', to: 'hub_categories#list'

    post 'documents', to: 'hub_categories#create'
    delete 'documents/:id', to: 'hub_categories#destroy'
    get 'documents/:id/request', to: 'hub_categories#request'
    get 'documents/:id/result', to: 'hub_categories#result'
    get 'documents/:id/word', to: 'hub_categories#word'
  end

  root to: 'hub_categories#index'
end

在这个限制之外,我还有更多的路线,比如/documents 等等。除了约束内的那些路由(例如,get 'documents')之外,我如何将任何内容匹配到'hub_categories#index'

我所有的尝试,比如约束块本身中的match '*', to: 'hub_categories#index', via: :all,都会出现这个错误:

ruby /Users/cdrum/.rvm/gems/ruby-2.5.0@aplus/bin/rspec(51938,0x7fff9ee53340) malloc: *** 对象 0x7fef03d21210 错误:已释放对象的校验和不正确 - 对象可能已修改被释放后。 在 malloc_error_break 中设置断点进行调试

题外话

该错误是由于 RVM 安装损坏所致,因此,如果您正在运行 rvm implode,则重新安装 RVM,然后是 Ruby,然后是您的 gem。

【问题讨论】:

  • 我认为与其匹配*,不如让它匹配*path。由于您使用的是子域约束,因此我自己很难对此进行测试。

标签: ruby-on-rails ruby ruby-on-rails-5


【解决方案1】:

把它放在SubdomainConstraint 块的底部就行了:

get '*path', to: 'hub_categories#index'

Rails 5 已弃用 match,我的错误是由于 RVM 安装损坏所致。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-05-11
    • 1970-01-01
    • 1970-01-01
    • 2012-08-09
    • 2015-10-22
    • 1970-01-01
    • 2017-11-27
    • 1970-01-01
    相关资源
    最近更新 更多