ruby-on-rails - Rails 成员路径前缀在更改路由后未更新
问题描述
我正在对 Rails 应用程序进行一些重构,并将一个表分成两个。这样做涉及我重命名原始模型,然后添加一个新模型并迁移数据。重命名表和模型后,我更改了资源的路由。它只更新了一些路由的前缀。这里发生了什么?这种资源过去被称为“服务”。以下是相关路线:
resources :notices, only: %i[index edit update destroy] do
get 'close', on: :member
get 'cancel_or_close', on: :member
get 'new_lockout', on: :member
post 'create_lockout', on: :member
get 'new_five_days', on: :collection
post 'create_five_days', on: :collection
post 'batch_update', on: :collection
# This bit of nuttiness is to solve an issue regarding submitting the same form to multiple actions
post 'edit_multiple', on: :collection, constraints: CommitParamRouting.new('create_pdfs'), action: 'create_pdfs'
post 'edit_multiple', on: :collection, constraints: CommitParamRouting.new('create_envelopes'), action: 'create_envelopes'
post 'edit_multiple', on: :collection, constraints: CommitParamRouting.new('mark_canceled'), action: 'mark_canceled'
post 'edit_multiple', on: :collection, constraints: CommitParamRouting.new('mark_processing'), action: 'mark_processing'
post 'edit_multiple', on: :collection, constraints: CommitParamRouting.new('mark_filed'), action: 'mark_filed'
post 'edit_multiple', on: :collection, constraints: CommitParamRouting.new('mark_out_for_service'), action: 'mark_out_for_service'
post 'edit_multiple', on: :collection, constraints: CommitParamRouting.new('mark_service_complete'), action: 'mark_service_complete'
post 'edit_multiple', on: :collection, constraints: CommitParamRouting.new('mark_reconciled'), action: 'mark_reconciled'
post 'edit_multiple', on: :collection, constraints: CommitParamRouting.new('mark_closed'), action: 'mark_closed'
post 'edit_multiple', on: :collection, constraints: CommitParamRouting.new('mark_billed'), action: 'mark_billed'
post 'edit_multiple', on: :collection, constraints: CommitParamRouting.new('get_unbilled_csv'), action: 'get_unbilled_csv'
post 'edit_multiple', on: :collection, constraints: CommitParamRouting.new('export_serves_csv'), action: 'export_serves_csv'
post 'edit_multiple', on: :collection, constraints: CommitParamRouting.new('batch_edit'), action: 'batch_edit'
end
这是'rake routes'的输出
close_serve GET /notices/:id/close(.:format) notices#close
cancel_or_close_serve GET /notices/:id/cancel_or_close(.:format) notices#cancel_or_close
new_lockout_serve GET /notices/:id/new_lockout(.:format) notices#new_lockout
create_lockout_serve POST /notices/:id/create_lockout(.:format) notices#create_lockout
new_five_days_notices GET /notices/new_five_days(.:format) notices#new_five_days
create_five_days_notices POST /notices/create_five_days(.:format) notices#create_five_days
batch_update_notices POST /notices/batch_update(.:format) notices#batch_update
edit_multiple_notices POST /notices/edit_multiple(.:format) notices#create_pdfs
POST /notices/edit_multiple(.:format) notices#create_envelopes
POST /notices/edit_multiple(.:format) notices#mark_canceled
POST /notices/edit_multiple(.:format) notices#mark_processing
POST /notices/edit_multiple(.:format) notices#mark_filed
POST /notices/edit_multiple(.:format) notices#mark_out_for_service
POST /notices/edit_multiple(.:format) notices#mark_service_complete
POST /notices/edit_multiple(.:format) notices#mark_reconciled
POST /notices/edit_multiple(.:format) notices#mark_closed
POST /notices/edit_multiple(.:format) notices#mark_billed
POST /notices/edit_multiple(.:format) notices#get_unbilled_csv
POST /notices/edit_multiple(.:format) notices#export_serves_csv
POST /notices/edit_multiple(.:format) notices#batch_edit
notices GET /notices(.:format) notices#index
edit_serve GET /notices/:id/edit(.:format) notices#edit
serve PATCH /notices/:id(.:format) notices#update
PUT /notices/:id(.:format) notices#update
DELETE /notices/:id(.:format)
如您所见,一些路由已经正确更新了它们的前缀,但其他路由仍然在它们的前缀中维护服务(成员路由)。为什么会这样?
编辑:这是一些模型代码:
class Notice < ApplicationRecord
belongs_to :client
belongs_to :affiant, optional: true
before_save :set_date_of_service, :set_default_billing_status, :set_default_affiant
class Affiant < ApplicationRecord
has_many :zip_codes
has_many :notices
class Client < ApplicationRecord
has_many :users
has_many :properties
has_many :notices
has_many :documents
解决方案
推荐阅读
- php - php替换标签或字符之间的一些字符串
- python - 当 List1 == List2 时,将 List3 中的条目与 List1 中的索引相加
- amazon-ec2 - 无法登录 EC2 实例
- java - Spring Data,Hibernate - 一对多关系不会为孩子们持续存在
- maven - maven-war-plugin 版本导致OOM
- css - 单击按钮时CSS过渡不起作用
- c++ - 对象集的排序不正确
- wpf - ContextMenu 绑定菜单项标题 MVVM
- asp.net - Autofac 在类库中解析
- oop - 实例变量 super 不能从另一个实例变量的定义中访问