Closed ktec closed 8 years ago
Here is what you can do:
def self.decorated_column(name, options = {}, &block)
column(name, options) do |model|
presenter = UserPresenter.decorate(model)
block ? block.call(presenter) : presenter.send(name)
end
end
decorated_column(:fullname)
decorated_column(:profile)
I saw a request to create a decorator before, maybe I'll add this feature to the gem soon.
Wonderful, thanks thats really helpful 👍
You could add a comment on the read me about this, it would be useful I think.
Sorry if this is the wrong place to ask, but I would like to wrap the models using a Presenter. To explain my situation here is an example:
Assume I wish to show a list of Users, I create the controller like this:
So I can decorate the model in the block with each column like this:
But as you can see I have to do this for every attribute I wish to decorate. Is there any way I can decorate the model before its passed to the block, so that I don't have to do it in every column definition?
Finally, thanks for a great gem, I've really enjoyed using it.