我有一个Rails引擎,我想为我的产品表生成动态路线。为此,我编写了此模块
dynamic_router.rb
System.IO.FileNotFoundException: 'Could not load file or assembly 'System.Security.Permissions, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.
I then run this in the NuGet Terminal: Install-Package System.Security.Permissions -Version 4.5.0
I then receive this error: System.IO.FileNotFoundException: 'Could not load file or assembly 'System.Drawing.Common, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.'
I then run the NuGet command: Install-Package System.Drawing.Common -Version 4.5.1
Then i receive this error: System.TypeLoadException: 'Could not load type 'System.Runtime.InteropServices.StandardOleMarshalObject' from assembly 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.'
I then run this in the Nuget terminal and reach a dead end.: Install-Package System.Runtime.InteropServices -Version 4.3.0
然后按如下所示在我的route.rb中运行它
module Insurance
module DynamicRouter
extend ActiveSupport::Concern
def self.load
Insurance::Engine.routes.draw do
# Skip dynamic route definition for now as it will fail when the DB doesn't exist
localized do
begin
Insurance::Product.all.each do |product|
get "/#{product.company.friendly_id}/#{product.friendly_id}", :to => "#{product.type.underscore.pluralize}#show", defaults: { id: product.friendly_id, company_id: product.company.friendly_id }, as: "#{product.type.underscore.pluralize}_#{product.friendly_id}"
end
rescue ActiveRecord::NoDatabaseError
end
end
end
end
def self.reload
Rails.logger.info "What made u reload"
Rails.application.routes_reloader.reload!
end
end
end
现在的问题是,当它生成路线时,它会这样生成
Insurance::Engine.routes.draw do
Insurance::DynamicRouter.load
end
当我期待这样的事情
insurance_cycle_insurance_products_aaa_a_driver_ms_path GET /ms/aaa/aaa-a-driver(.:format)
insurance/insurance/cycle_insurance_products#show {:id=>"aaa-a-driver", :company_id=>"aaa", :locale=>"ms"}
不确定如何解决这种不允许两次定义 insurance_cycle_insurance_products_aaa_a_driver_ms_path GET /ms/aaa/aaa-a-driver(.:format)
insurance/cycle_insurance_products#show {:id=>"aaa-a-driver", :company_id=>"aaa", :locale=>"ms"}
的问题。
感谢您的帮助