在 Rails 应用程序中实现换肤的最佳方法是什么

发布于 2024-12-10 09:43:53 字数 431 浏览 3 评论 0原文

我正在使用 Rails 构建几个非常相似的站点。我想将它们实现为一个能够响应多个域的 Rails 应用程序,并根据域名更改所呈现的内容和处理逻辑。我需要为每个站点更改/皮肤的区域是:

  • 视图:页面上的字段因站点而略有不同。有些站点比其他站点具有更多/不同的字段,但有些站点在所有
  • 模型中都是通用的(似乎最好通过为主模型定义一个超类来实现此目的,该超类会为每个站点变化并实现子类)
  • 控制器逻辑。有很多相似之处,但有一些小的处理差异,包括处理
  • CSS 的模型子类(这看起来相当简单)

我已经实现了一种机制,使当前的域/应用程序名称对视图、控制器和模型可见。

我正在考虑为每个站点定义一个视图部分,并使用 ERB 逻辑来包含正确的部分。控制器似乎是最不明显的部分。

非常感谢任何建议。

干杯 保罗

Using Rails, I am building several sites which are very similar. I want to implement these as one Rails app answering to multiple domains, and change what is presented and the processing logic based on the domain name. The areas I need to change/skin per site are:

  • Views: The fields on a page differ slightly by site. Some sites have more/different fields than others, but there are some that are common across all
  • Models (which seems best to do this by defining a super class for the main model which varies and implement a subcalss for each site)
  • Controller logic. There is a lot of similarity but a few small processing differences, including which Model subclass to deal with
  • CSS (which seems fairly straight forward)

I have already implemented a mechanism which makes the current domain/app name visible to the views, controllers and models.

I was thinking of defining a view partial per site and using ERB logic to include the right one. The controllers seem like the least obvious part.

Any suggestions very much appreciated.

Cheers
Paul

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

于我来说 2024-12-17 09:43:53

我已经为我们的应用程序 HiringThing (http://www.hiringthing.com) 实现了类似的功能。

为此,我们在应用程序控制器上使用 before_filter 来解析 request.host 并确定请求针对哪个网站。然后设置一个变量@site,我们在视图、控制器和模型中引用该变量以确定运行时的版本控制要求。

I have implemented something similar for our application, HiringThing (http://www.hiringthing.com)

To do so, we use a before_filter on the application controller that parses request.host and determines what website the request is for. That then sets a variable @site that we reference in views, controllers and models to determine versioning requirements at runtime.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文