1
I would like to add the following methods to my Models when presented in the View, for example, can_be_showed
, can_be_edited
, can_be_destroyed
, among others, but in some cases these methods may depend on the Controller, such as depending on the user who is logged in.
I’ve tried using the pattern Presenter, but I found many problems, such as to render the Persenter like 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 any tips, followed by example? , I would like something that would give me the opportunity to reuse as much code as possible.
Have a look at https://github.com/elabs/pundit
– GuiGS
I heard about Draper Decorator at the Rails 2014 https://github.com/drapergem/draper conference, first I will test this, something I inform the result here
– user5020