不确定这是词尾变化还是STI。
我有一个模型Activity,我还有一个Integrity通过STI继承的类。在该模型中,我有以下内容:
class Integrity < Activity
def self.model_name
Activity.model_name
end
end我已经看到它可以帮助在STI下进行路由。
我设置了我的路线:
resources :integrity, controller: :activities, type: 'Integrity'和词尾变化:
inflect.plural 'integrity', 'integrity'
inflect.singular 'integrity', 'integrity'
inflect.irregular 'integrity', 'integrity'这似乎是可行的:
>> url_for [:new, :integrity]
=> "/integrity/new"除索引路由外:
>> url_for [:integrity]
!! #<ActionController::UrlGenerationError: No route matches {:action=>"show", :controller=>"activities", :type=>"Integrity"}, missing required keys: [:id]>但这是可行的:
>> url_for [:integrity, :index]
=> "/integrity"我的问题是,对于我的其他STI类的“正常”变化,我有这样的变化:
>> url_for [:operations]
=> "/operations"如何让rails将:integrity识别为索引路由?我希望所有的STI类都有相同的视图文件,然后有一个共同的结构来构建动态路由等。我不能让一些人需要额外的:index,而有些人则不需要。
发布于 2019-11-24 11:02:34
将单个名称传递给resources时,index路由将变为name_index_path
在您的例子中是integrity_index_path或url_for(:integrity, :index)
您可以添加自定义路由
get "integrity", to: 'activities#index', type: 'Integrity'
resources :integrity, controller: :activities, type: 'Integrity'然后就可以执行url_for(:integrity)了
发布于 2019-11-26 03:52:34
我想明白了--在问题中张贴这个可能会触发一个答案:
我有这样的经历:
resources :integrity, controller: :activities, type: 'Integrity'当我本应该拥有:
resources :integrities, controller: :activities, type: 'Integrity'同时还包括:
inflect.irregular 'integrity', 'integrities'我有一个想法,我需要在我的应用程序中保留“正常”的复数Integrity。这就消除了所有的自定义路由等。
https://stackoverflow.com/questions/59014145
复制相似问题