I have in my model:
def presenter
@presenter ||= ProfilePresenter.new(self)
@presenter
end
The ProfilePresenter is a class that has methods like, get_link(), get_img_url(size), get_sex(), get_relationship_status() and other methods that have not to do with the model, not even with the controller but is used multiple times in the view.
So now i use them by doing this:
Profile.presenter.get_link
# or
Profile.presenter.get_img_url('thumb') # returns the path of the image. is not used to make a db query
Sincerelly i think i missed out the real concept of presenters.. but this is what m trying to archive, how can be called this?
Normally this sort of thing is handled via helper methods, such as:
It is unfortunate you cannot layer in Presenter-style helper methods that extend a Model at view time. They need to be called in a procedural manner with a parameter, kind of anti-OO.
The Presenter approach is not fully supported in the Rails MVC area because it needs to bind to a view in order to have access to the various helper methods required to properly render content, plus information about the session that may impact the presentation.
A more robust approach might be to do something like this:
This would show up in your view as something like:
You can simplify calling this by making a helper method that does something mildly crazy like:
This means you have a much simpler call: