且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

是否有可能改变一个Rails项目的文件夹结构?

更新时间:2023-11-23 11:01:04

我想你可能试图解决在稍微放错了地方你的问题。如果你需要同时支持应用程序的多个版本,并能够使修复他们独立等等等等,用git进行版本控制(如果你没有的话),并创建为每个版本单独的分支听起来像的方式去给我。 (我敢肯定,你可以做类似与Mercurial,SVN等,但Git的似乎是Rails的事实上的标准)。

下面是约分支的一些信息的链接: HTTP ://git-scm.com/book/en/Git-Branching-Basic-Branching-and-Merging

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

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.

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

can be rearranged to this?

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

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).

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