创造不同的“流派”我的网站(即,我有一个 stackoverflow 等效项,并且我想创建一个 serverfault 等效项)
我的网站 Rap Genius 解释说唱歌词。我想创建一个新网站 Rock Genius,用于解释摇滚歌词 - 否则它将是相同的(相同的布局,相同的数据库架构;就像 Serverfault 与 Stackoverflow 一样)
最好的方法是什么?
方法 1:分叉代码
分叉 Rap Genius 代码,更改相关部分(例如,“Rap”->“Rock”),创建一个新数据库并进城。
- 优点:可以快速运行
- 缺点:向两个应用程序添加功能会有些痛苦。此外,也不可能让 Rap Genius 在数据库级别访问 Rock Genius 的数据
方法 2:将其保留为单个应用程序
每当请求进入我的应用程序时,请检查域。如果是 rapgenius.com
,请将 SITE_NAME
常量设置为 “rapgenius”
。在面向用户的实体(歌曲、博客文章等)上创建一个 genre
字段,并更新我的查询以根据 SITE_NAME
使用正确的流派
在上面创建一个抽象层面向用户的字符串,我可以编写 <%=welcome_message %>
而不是 Welcome to Rap Genius!
并拥有 welcome_message()
考虑 SITE_NAME
- 优点:灵活性很大
- 缺点:工作量很大!
想法?
My site, Rap Genius, explains rap lyrics. I want to create a new site, Rock Genius, that explains rock lyrics – otherwise it'll be the same (same layout, same DB schema; like Serverfault is to Stackoverflow)
What's the best way to do this?
Approach 1: Fork the code
Fork the Rap Genius code, change the relevant parts (e.g., "Rap" -> "Rock"), create a new database and go to town.
- Pros: Can get it working quickly
- Cons: It'll be somewhat painful to add a feature to both applications. Also it'll be impossible to give Rap Genius access to Rock Genius' data at the DB level
Approach 2: Keep it a single application
Whenever a request comes into my application, check the domain. If it's rapgenius.com
, set the SITE_NAME
constant to "rapgenius"
. Create a genre
field on user-facing entities (songs, blog posts, etc) and update my queries to use the correct genre based on the SITE_NAME
Create a layer of abstraction above user-facing strings to that I can write <%= welcome_message %>
instead of Welcome to Rap Genius!
and have welcome_message()
take SITE_NAME
into account
- Pros: Lots of flexibility
- Cons: Lots of work!
Thoughts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
第二种方法对我来说听起来更好。
您已经强调了主要的优点和缺点 - 这肯定会需要更多工作,但维护起来会更友好。有没有可能出现第三、第四、第五个站点?如果是这样,毫无疑问这是正确的方法。
您还可能能够更轻松地共享用户帐户、声誉和任何其他类型的基于社区的功能。
也许值得看看 Rails i18n 的东西,用于根据域名“翻译”静态文本。这样您就可以避免为每个要显示的字符串编写辅助方法。
然后您应该能够非常轻松地“特许经营”该网站 - 添加静态字符串的翻译、新域的句柄,也许还有一些网站特定的图像或 CSS,然后您就完成了!
The second approach sounds better to me.
You've already highlighted the main pros and cons - it will definitely be more work, but will be much friendlier to maintain. Is there any chance of a third, fourth, fifth site? If so, there's no question that this is the right way to go.
You'll likely also be able to share user accounts, reputation, and any other kind of community based functionality more easily.
It might be worth looking at Rails
i18n
stuff for 'translating' static text, based on the domain name. That way you could avoid writing helper methods for every string you want to display.Then you should be able to 'franchise' the site really easily - add translations of static strings, a handle for the new domain, and maybe some site specific images or CSS and you're done!