Note we're using the `call` method (which is equivalent to adding an ERB file) because we were getting an error calling `render` from the `dates` method: ``` ActionView::Base#lookup_context delegated to view_renderer.lookup_context, but view_renderer is nil: ``` It might be because we aren't rendering the `Adming::Budgets::DurationComponent` but just calling one method, and so there's no view context in this case.
26 lines
504 B
Ruby
26 lines
504 B
Ruby
class Admin::Budgets::DurationComponent < ApplicationComponent
|
|
attr_reader :durable
|
|
|
|
def initialize(durable)
|
|
@durable = durable
|
|
end
|
|
|
|
def dates
|
|
Admin::DateRangeComponent.new(start_time, end_time).call
|
|
end
|
|
|
|
def duration
|
|
distance_of_time_in_words(durable.starts_at, durable.ends_at) if durable.starts_at && durable.ends_at
|
|
end
|
|
|
|
private
|
|
|
|
def start_time
|
|
durable.starts_at
|
|
end
|
|
|
|
def end_time
|
|
durable.ends_at - 1.second if durable.ends_at.present?
|
|
end
|
|
end
|