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.
27 lines
559 B
Ruby
27 lines
559 B
Ruby
class Admin::DateRangeComponent < ApplicationComponent
|
|
attr_reader :start_time, :end_time
|
|
|
|
def initialize(start_time, end_time)
|
|
@start_time = start_time
|
|
@end_time = end_time
|
|
end
|
|
|
|
def call
|
|
safe_join([formatted_start_time, "-", formatted_end_time], " ")
|
|
end
|
|
|
|
private
|
|
|
|
def formatted_start_time
|
|
formatted_date(start_time) if start_time.present?
|
|
end
|
|
|
|
def formatted_end_time
|
|
formatted_date(end_time) if end_time.present?
|
|
end
|
|
|
|
def formatted_date(time)
|
|
time_tag(time, format: :short_datetime)
|
|
end
|
|
end
|