Files
nairobi/app/components/budgets/budget_component.rb
Javi Martín 291620abf7 Use tag.attributes to set conditional HTML attributes
Using an `if..else` block made the code harder to follow since the
opening tag was inside the block but the closing tag was outside it.
Moreover, it didn't work well with HTML Beautifier (a gem we're going to
introduce to manage ERB indentations).
2025-03-07 16:02:07 +01:00

22 lines
468 B
Ruby

class Budgets::BudgetComponent < ApplicationComponent
attr_reader :budget
use_helpers :attached_background_css
def initialize(budget)
@budget = budget
end
private
def html_attributes
if budget.image.present?
{
class: "budget-header with-background-image",
style: attached_background_css(polymorphic_path(budget.image.variant(:large)))
}
else
{ class: "budget-header" }
end
end
end