【发布时间】:2013-06-09 18:55:04
【问题描述】:
场景:
- 一个主要的 Rails 应用程序
- 各种 Rails 引擎,安装在主要 Rails 应用程序 (routes.rb) 中
现在假设我有一个名为“Engine”的引擎,里面有一个名为“Topic”的模型。
类似Engine::Topic < ActiveRecord::Base
现在在这个引擎中,如果我必须为Topic 的任何实例生成路由,我会执行以下操作:
@topic = Engine::Topic.first
# inside helpers/views, i can write the below statement
url_for ([@topic])
# and it will give me exact "show" route for this topic. Like "/engine/topic/1"
# But this works only inside engines. If i write this inside main Application,
# it gives an error "undefined method 'topic_path'"
现在我怎样才能使它成为一个通用模式?
意味着我可以拥有任何模型的任何对象(来自各种引擎)并且我能够以干净的方式找出它的路线?
【问题讨论】:
标签: ruby-on-rails url activerecord routes helper