Move progress bars form partial to a component
This way we can move some of the view logic to the Ruby class. It'll also make it easier to write tests for it.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<%= render "shared/globalize_locales", resource: @progress_bar %>
|
||||
<%= render "shared/globalize_locales", resource: progress_bar %>
|
||||
|
||||
<%= translatable_form_for @progress_bar, url: admin_polymorphic_path(@progress_bar) do |f| %>
|
||||
<%= translatable_form_for progress_bar, url: admin_polymorphic_path(progress_bar) do |f| %>
|
||||
|
||||
<div class="row">
|
||||
<div class="small-12 medium-6 column">
|
||||
@@ -16,7 +16,6 @@
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<% progress_options = { min: ProgressBar::RANGE.min, max: ProgressBar::RANGE.max, step: 1 } %>
|
||||
<div class="row">
|
||||
<div class="small-12 medium-6 large-2 column">
|
||||
<%= f.label :percentage %>
|
||||
15
app/components/admin/progress_bars/form_component.rb
Normal file
15
app/components/admin/progress_bars/form_component.rb
Normal file
@@ -0,0 +1,15 @@
|
||||
class Admin::ProgressBars::FormComponent < ApplicationComponent
|
||||
include TranslatableFormHelper
|
||||
include GlobalizeHelper
|
||||
attr_reader :progress_bar
|
||||
|
||||
def initialize(progress_bar)
|
||||
@progress_bar = progress_bar
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def progress_options
|
||||
{ min: ProgressBar::RANGE.min, max: ProgressBar::RANGE.max, step: 1 }
|
||||
end
|
||||
end
|
||||
@@ -12,4 +12,4 @@
|
||||
|
||||
<h2><%= bar_title %></h2>
|
||||
|
||||
<%= render "form" %>
|
||||
<%= render Admin::ProgressBars::FormComponent.new(@progress_bar) %>
|
||||
|
||||
@@ -6,4 +6,4 @@
|
||||
|
||||
<h2><%= t("admin.progress_bars.new.creating") %></h2>
|
||||
|
||||
<%= render "form" %>
|
||||
<%= render Admin::ProgressBars::FormComponent.new(@progress_bar) %>
|
||||
|
||||
Reference in New Issue
Block a user