是否可以更改 Rails 项目中的文件夹结构? [英] Is it possible to alter the folder structure in a Rails project?

查看:24
本文介绍了是否可以更改 Rails 项目中的文件夹结构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我来自 .Net MVC 背景,希望在 RoR 中做一个项目.具体来说,我正在开发一个 REST api.

I'm coming from the .Net MVC background looking to do a project in RoR. Specifically I'm develop a REST api.

我将描述我的想法,希望您能指引我走向正确的方向.我的 api 必须支持版本,而对 api 进行版本控制的最可靠方法是为每个版本复制代码.这样在一个版本中修复问题不会影响其他版本.当谈到在 .NET MVC 中这样做时,区域是你最好的朋友,因为每个版本的源文件可以通过使用区域很好地分割.

I will describe my thinking and hopefully you could steer me in the right direction. My api must support versions and the most robust way to version an api is to duplicate the code for every version. That way fixing issues in one version doesn't effect other versions. When it comes to doing that in .NET MVC, areas are your best friend because source files for each version can nicely be segmented through using areas.

所以我的问题是:在 RoR 中是否可以更改目录结构以便此层次结构

So my question is: In RoR is it possible to change the directory structure so this hierarchy

app/
  controllers
    /v1
      c1_controller.rb
      c2_controller.rb
    /v2
      c1_controller.rb
      c2_controller.rb
  models/
    /v1
      m1.rb
      m2.rb
    /v2
      m1.rb
      m2.rb
  views/
    /v1
      view1.html.erb
      view2.html.erb
    /v3
      view1.html.erb
      view2.html.erb

可以改成这样吗?

app/
  v1/
    controllers/
      c1_controller.rb
      c2_controller.rb
    models/
      m1.rb
      m2.rb
    views/
      view1.html.erb
      view2.html.erb
  v2/
    controllers/
      c1_controller.rb
      c2_controller.rb
    models/
      m1.rb
      m2.rb
    views/
      view1.html.erb
      view2.html.erb

推荐答案

我认为您可能试图在稍微错误的地方解决您的问题.如果您需要同时支持多个版本的应用程序,并且能够独立修复它们等,使用 git 进行版本控制(如果您还没有)并为每个版本创建一个单独的分支听起来像这样去找我.(我相信你可以用 Mercurial、SVN 等来做类似的事情,但 Git 似乎确实是 Rails 的事实上的标准).

I think you may be trying to solve your problem in slightly the wrong place. If you need to support several versions of your application simultaneously, and be able to make fixes to them independently etc etc, using git for your version control (if you're not already) and creating a separate branch for each version sounds like the way to go to me. (I'm sure you could do similar with Mercurial, SVN etc but Git does seem to be the Rails de facto standard).

这是一些有关分支的信息的链接:http://git-scm.com/book/en/Git-Branching-Basic-Branching-and-Merging

Here's a link to some info about branching: http://git-scm.com/book/en/Git-Branching-Basic-Branching-and-Merging

这篇关于是否可以更改 Rails 项目中的文件夹结构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆