Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hierarchic MVC in Rails 3?

I've read about HMVC (Hierarchic Model View Controller) and it's flexible structure.

Have a look at this picture:

http://techportal.inviqa.com/wp-content/uploads/2010/02/MVC-HMVC.png

I wonder if the Rails 3 plugins are the answer to HMVC in Rails 3?

like image 565
never_had_a_name Avatar asked Aug 25 '10 21:08

never_had_a_name


2 Answers

Based on the comments to Toby's answer it seems that you would like to be able to have MVC apps used as a component within a new app. Rails Engines (See http://rails-engines.org) provides this functionality. You simply install the engines gem and place apps in vendor/plugins and its modles/views/controller are all accessible.

This does not really conform to HMVC where the controllers in the new app delegate to other controllers. But like Toby I do not see the advantage of that.

What is nice about the Engines approach is that you can over ride any of models in the plugin by just adding a version of the model to the new apps app/model folder (same applies for views and controllers)

I have overidden app/views/layouts to give my Authentication app/plugin the same look and feel as the application it is included in.

For Rails 3 Railtie takes the place of engines and is officially supported (and actually used - Action Mailer is a Railtie plugin. I have not used it myself yet though.

Check it out at http://edgeapi.rubyonrails.org/classes/Rails/Railtie.html

A nice write up on it is also here http://www.igvita.com/2010/08/04/rails-3-internals-railtie-creating-plugins/

like image 95
Will Avatar answered Sep 19 '22 12:09

Will


Rails has had plugins for a long time.

I doubt there is a technical reason why a controller couldn't dispatch to another controller, passing the request object along a chain. I just don't know what you gain by doing so - the diagram looks like spaghetti.

To me it's a misuse of MVC. I would suggest it is much simpler and more maintainable to push logic into lower-level models and classes and create a single controller that fronts the this logic, rather than creating a chain of controllers.

like image 43
Toby Hede Avatar answered Sep 21 '22 12:09

Toby Hede