Hierarchic MVC in Rails 3?
Asked Answered
B

4

9

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?

Bekha answered 25/8, 2010 at 21:53 Comment(0)
F
3

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/

Floreneflorentia answered 9/9, 2010 at 14:58 Comment(3)
What are the differences/advantages of using Railties over Rails plugins?Bekha
A justification for Railtie can be found here engineyard.com/blog/2010/…Floreneflorentia
From the Railtie site "Developing a Rails extension does not require any implementation of Railtie, but if you need to interact with the Rails framework during or after boot, then Railtie is what you need to do that interaction."Floreneflorentia
J
2

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.

Jerrybuilt answered 25/8, 2010 at 22:15 Comment(5)
I dont agree here. Maybe i'm adding some new features that could be stand alone...then it's good to have it as a standalone MVC component rather than incorporating everything in the main application MVC, thus making it re-usable for other projects. Plus, everyone of those MVC components you see in the diagram could be from a 3rd party vendor. I wouldn't mix them inside my main application MVC. The diagram doesn't seem spaghetti to me, it seems to be very well structured. Delegate rather than throwing everything in one big chunk that will get bigger and bigger.Bekha
I think it's a leaky abstraction. What advantages does it bring that a well-structured object layer handling your business logic can't achieve in a more granular and easily tested fashion?Jerrybuilt
And voting me down because I have serious and well-considered reservations about the architectural style is kinda harsh.Jerrybuilt
hede. Maybe it's not my job to test those 3rd party MVC components. They are like add-ons that I can add/delete to/from the application itself. I voted down for "The diagram looks like spaghetti" phrase. If you added "to me" I think it would sound better and I will up-vote you again :)Bekha
cause it sounded too harsh to the HMVC...but I forgive you:) the voting button is locked..you have to edit the answer a bit so i can upvote =)Bekha
K
1

In the Rails 3 blog post, DHH mentioned the Cells project. I haven't used it but I am going to check it out.

The cart example shows well how that kind of functionality might clean up your application code. Code which retrieves data should be placed somewhere in controller. In every action or in a before filter. The Cell seems to be much better solution.

Kinross answered 8/9, 2010 at 6:57 Comment(0)
C
0

Please look at this rubyonrails-talk post: https://groups.google.com/forum/#!topic/rubyonrails-talk/0c4TT7UOGCw

Clovis answered 1/6, 2014 at 18:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.