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
Checkout this page, it will give you some insights on directory structure for Rails 3+ projects:
http://edgeapi.rubyonrails.org/classes/Rails/Engine.html
Don't be scared with the fact that it's about Engines, it states in the very beginning: every Rails App is an Engine.
UPDATE: Never had an opportunity to do that myself, but according to that page and this, you should add the following thing into your
config/application.rb
withinclass Application < Rails::Application
:Check this project as an example: https://github.com/forker/multiversion
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
If you're always on a system that supports symlinks, then it might be simpler to just symlink
etc. Or alternatively the other way around.
Rails would then read
app/controllers/v1/c1_controller.rb
as usual and assume it's in the V1 namespace ("class V1::C1Controller
").Remember to make the links relative.