Plugins - Real Components
Add to favoritesThis plugin allows for the use of "real components".
Real Components extend rails component providing them the possibility to act as "subroutines", returning to whoever is calling them.
The objective is to build a basis upon which I can build a infrastructure for automatically scaffolding relationships
For instance, imagine that you have three classes: Person, Biography and Event. A Person has one biography that in turn has many events. By default, Rails maps a controller and several view files for each class. Say that I want to be able to edit a concrete event in one’s biography from the show view of person. Actually either:
- I create I new action in the persons controller. But editing an event should conceptually be handled by the events controller
- I delegate into the events controller, by creating an action ‘editintoperson’ that when is finished returns the user to the view of the person that originated the call.
A more elegant solution will be to be able to put into the already existing event edit action links that automagically change to the person view if they have been called from there or to the default view otherwise. This is what RealComponent does.
To use it, you only need to unpack into /vendor/plugins and then you get the following helping functionalities:
- In order to call a component so that it is able to return:
<%= render_component :stk => true <…whatever you had here previously…> %>
- In order to insert a link so that we return to the this view after following it:
<%= link_to :stk => true <…link…> %>
- In order to insert a link that returns from a component to whoever called it (or if we are not inside a call, applies the default behaviour):
<%= link_to :rtn => true <…default behaviour here…> %>
So the question at this point is: are you simply implementing the functionality of a back button in a browser. The answer is that Real Components provide a bit more, concretely:
- After an update, from the controller if everything was ok, we will usually like to return to the caller. We can do this inside the controller:
redirect_to :rtn => true <…where to go to if nobody called us…>
- This can also be used into form_tags and any other tag that generates a url.
