我管理着几个Rails站点,它们的源代码非常相似,但有一些小的差异(大多数但不是所有的差异都存在于数据库中)。我希望每个网站都有相同的基础源代码与任何源代码的差异驻留在自定义文件,覆盖基础源代码。例如,如果一个站点有一个照片竞赛,该站点将有一个其他站点没有的特殊视图文件,但所有站点都将具有相同的默认视图文件(只有包含该竞赛的站点将被覆盖)。这会是Rails引擎的任务吗?如果不是(或者如果有更好的方法),你会怎么做呢?
谢谢。
编辑:这是另一个例子--一个网站(我管理的三个网站中的一个)需要在某个页面上有特殊文本。我希望这三个网站上的这个页面的视图保持不变,我不想在视图中决定是否显示此文本的条件代码。相反,我更喜欢为不同的站点提供一个独立的视图来覆盖默认视图(这样可以更容易地管理站点之间的差异)。
发布于 2012-08-26 12:04:28
你问题的直接答案(见下文)。对你问题的解释越长,http://edgeguides.rubyonrails.org/engines.html#overriding-views。如果你还有问题,请告诉我(引擎是我的爱好)。
app1
|- app/views/photo_contests
| |- index.html.erb # => custom view template #1
|
\- Gemfile (gem 'common_engine')
app2
|- app/views/photo_contests
| |- index.html.erb # => custom view template #2
|
\- Gemfile (gem 'common_engine')
common_engine
|
|- app/controllers/PhotoContentsControllers.rb
| |- index
| |- show
| |- vote
|
|- app/models/photo_contest.rb
|
|- app/views/photo_contents
| |- index.html.erb
| |- show.html.erb
| |- vote.html.erb
|- config/routes.rb
|- lib/common_engine/engine.rb
|- lib/common_engine.rb
\- common_engine.gemspechttps://stackoverflow.com/questions/8735053
复制相似问题