Presenter in Rails
My first idea.
I feel this is a waste of method_missing.
# app/model/application_model.rb class ApplicationModel < ActiveRecord::Base self.abstract_class = true def method_missing(name, *args, &block) begin klass = eval "#{self.class.to_s}Presenter" presenter = klass.new(self) method_name = name.to_s presenter.send(method_name) rescue super end end end # app/models/user.rb class User < ApplicationModel # ... end # app/presenters/user_presenter.rb class UserPresenter # ... end
My second idea.
This is more simple than first idea.
# app/models/user.rb class User < ActiveRecord::Base # ... include PostPresenter end # app/presenters/post_presenter.rb module PostPresenter # instanse methods module ClassMethods # class methods end def self.included(mod) mod.extend ClassMethods end end
hmm...
I am looking for better idea than these.