I would like to add the following methods to my Models when presented in the View, such as can_be_showed
, can_be_edited
, can_be_destroyed
, among others, however in some cases these methods may depend on Controller , such as depending on the user who is logged in.
I have tried using the Presenter pattern, but I encountered a lot of problems, such as rendering Persenter as a Model:
<%= render my_presenter %>#=render partial: 'my_models/my_model, locals: {my_model: @my_model}
Pass it as a parameter to a routing method:
link_to 'title', edit_my_model(@my_presenter)
Or create a form based on it
form_for(@my_presenter) do |f|
Would anyone have a hint, followed by an example? I would like something that would give me the opportunity to reuse as much code as possible.