How to share methods between presenters in Ruby on Rails 4

0

I would like to add methods to my template through a Presenter, but some methods are shared among other presenters.

Ex: os métodos 'pode_ser_mostrado?', 'pode_ser_editado?', 'pode_ser_excluido?'  

What is the best way, to create a base presenter to be extended by others ?, or create a mixin included by the presenters?

Example:

class ModeloPresenter < BasePresenter
end

or

class ModeloPresenter
  include 'base_presenter'
end

In case how to implement?

Example how to use the methods:

<%= link_to 'Mostrar', show_usuario(usuario.id) if UsuarioPresenter.pode_ser_mostrado? %>

<%= link_to 'Mostrar', show_cliente(cliente.id) if ClientePresenter.pode_ser_mostrado? %>

<%= link_to 'Mostrar', show_local(local.id) if LocalPresenter.pode_ser_mostrado? %>

I also accept if there is a suggestion for a better way to implement it.

    
asked by anonymous 18.01.2015 / 05:11

1 answer

0

Easy, easy:

class MeuModelo << ActiveRecord::Base
  def pode_ser_mostrado?
    # implementação do método
  end
end
    
18.01.2015 / 19:50