Reputation: 6838
I've been struggling with the right way to design a Rails model/controller for a dashboard/portal that can support easy/clean widget development. I've already (as a diversion) wrote a jQuery/jQuery-UI/CSS basic view that has worked out the column/order HTML and controls to reorder/minimize/remove the widgets, and now I'm coming back to how best to design the model and controller.
As a central place to find all widget information, I have a Widget model. (as a non-ActiveRecord for now) Ideally I'd like to have the Widget Index view simply take the Widgets from the Controller, and the model would contain widget attributes needed to render the view. This would include widget "partial" and "controller" attributes that the view could use to render a specific widget's partial view in my Dashboard view.
I don't want to have to overload my Widget controller with a bunch of potential widget specific data that their partial view might use. Instead I want to have the partial render itself, by just specifying the widget's partial and controller to use. Then the partial view and controller can do whatever they need to for that widget.
Widget Controller Index --> render @widgets --> widget1 widdget1_controller/partial view1
\ \-> widget2 widdget2_controller/partial view2
\--> widget3 widdget3_controller/partial view3
The Dashboard model would contain column, order, partial view, controller.
The Widget specific partial Views and Controllers would would located under a sub-folder of the controllers and views/widget folders to keep things clean.
I'm hoping this will help when trying to add AJAX support. Each widget controller can handle their own Controller Actions (like editing the widget or saving something) and I can have the client browser make AJAX calls to the partial for updated information without having to call the original Widget Controller, etc...
What do you guys think? Do you have a better suggestion?
Upvotes: 3
Views: 2996
Reputation: 1732
This might be to late now, but there is an extension on cells called Apotomo, which basically extends cells with actions and ajax to make little widgets. It's pretty awesome, and they have tutorials on doing the whole widget thing you're talking about. If this is to late, I would guess it would be pretty easy to port your cells code over to the widgets as they're very similar.
Upvotes: 2