def self.percent(*keys)
keys.each do |key|
define_method(key) do
h.number_with_precision(object.send(key) * 100.0, precision: 1)
end
define_method("display_#{key}") do
h.number_to_percentage(object.send(column_name) * 100.0, precision: 1)
end
class CompanyDecorator < BaseDecorator
delegate_all
currency :budget, :actual
end
class BaseDecorator < Draper::Decorator
delegate_all
def self.currency(*keys)
keys.each do |key|
define_method(key) do
h.number_with_precision(object.send(key), precision: 2)
end
class BaseDecorator < Draper::Decorator
delegate_all
def self.currency(*keys)
keys.each do |key|
define_method(key) do
end
define_method("display_#{key}") do
class BaseDecorator < Draper::Decorator
delegate_all
def self.currency(*keys)
end
end
class CompanyDecorator < BaseDecorator
delegate_all
def budget
h.number_with_precision(object.budget, precision: 2)
end
def display_budget
h.number_to_currency(object.budget, precision: 0)
class CompanyDecorator < BaseDecorator
delegate_all
currency :budget
end
# app/decorators/company_decorator.rb
class CompanyDecorator < BaseDecorator
delegate_all
end
# app/decorators/base_decorator.rb
class BaseDecorator < Draper::Decorator
delegate_all
end
class CompanyDecorator < BaseDecorator
delegate_all
currency :budget, :actual
percent :percent_budget_spent
end
NewerOlder