amatsuda/active_decorator

Decorating other Ruby objects

Closed this issue · 1 comments

I'm trying to decorate an API response object but it's not working...

class RegistrationsController < Devise::RegistrationsController
  helper_method :orders
  def orders
    @orders ||= PreApproval.orders resource.subscription_code # returns an array of PagSeguro::SubscriptionPaymentOrder
  end
end

# app/decorators/order_decorator.rb
module PagSeguro::SubscriptionPaymentOrderDecorator
  def something
  end
end

# on the view (triggers NoMethodError)
orders.first.something

Any ideas?

It works now. I've added this code to ApplicationController then decorated it manually.

class ApplicationController < ActionController::Base
  def decorate(obj)
    ActiveDecorator::Decorator.instance.decorate(obj)
  end
end