Merb Parts (or) Components in Merb
Merb Parts are analogous to Rails Components, except without the myriad shortcomings. Yehuda Katz gives a good introduction to them on his blog.
A few things not covered in Yehuda’s blog post:
- merb-gen has a generator for part controllers. To generate a part controller for displaying a tag cloud, you might do somethine like:
merb-gen part_controller Tags - Part controller support is implemented in merb-more, not merb-core. You have to add merb-parts as a dependency in your init.rb file:
dependency 'merb-parts'
Render A Part’s Action From Another Controller
In the off chance that you want to render a part controller’s action from a controller, you can create an instance of the controller and then call its _dispatch method.
class Nav < Application
def show
part = NavPart.new(self)
render part._dispatch(:action_name)
end