diff --git a/app/models/concerns/with_inheritance.rb b/app/models/concerns/with_inheritance.rb index 106b7e324ae2f6770d2b7c108454ddac7946e638..7257f9c53b9d8fd5783d9475264c5034df5d8805 100644 --- a/app/models/concerns/with_inheritance.rb +++ b/app/models/concerns/with_inheritance.rb @@ -5,22 +5,12 @@ module WithInheritance def self.rich_text_areas_with_inheritance(*properties) properties.each do |property| has_rich_text property - has_inheritance_methods property - end - end - - def self.values_with_inheritance(*properties) - properties.each do |property| - has_inheritance_methods property - end - end - - def self.has_inheritance_methods(property) - define_method :"best_#{property}" do - best(property) - end - define_method :"best_#{property}_source" do - best_source(property) + define_method :"best_#{property}" do + best(property) + end + define_method :"best_#{property}_source" do + best_source(property) + end end end end @@ -35,8 +25,6 @@ module WithInheritance def best_source(property) value = send(property) return nil if !value.blank? # There is a value, no inheritance needed - best_value = best(property) - best_value.is_a?(ActionText::RichText) ? best_value.record - : ancestors.detect { |ancestor| ancestor.public_send(property) == best_value } + best(property)&.record end end diff --git a/app/models/education/program.rb b/app/models/education/program.rb index 0924ffff2042bc7c8e73d8924102c8abb53ce7a1..75f1e25749cc238ca8266dd25c58cf56ce149b6b 100644 --- a/app/models/education/program.rb +++ b/app/models/education/program.rb @@ -47,8 +47,6 @@ class Education::Program < ApplicationRecord :pricing, :registration - values_with_inheritance :description - attr_accessor :skip_websites_categories_callback has_one_attached_deletable :featured_image diff --git a/app/views/admin/education/programs/_form.html.erb b/app/views/admin/education/programs/_form.html.erb index 11fe6ccbfec5b975415ed49b4cde99154baa8c51..9c430556d4bba8ba8c48d5fa60b2744b0add82b2 100644 --- a/app/views/admin/education/programs/_form.html.erb +++ b/app/views/admin/education/programs/_form.html.erb @@ -48,7 +48,7 @@ <h5 class="card-title mb-0"><%= t('education.program.useful_informations') %></h5> </div> <div class="card-body"> - <%= render 'admin/education/programs/forms/input_with_inheritance', f: f, property: :description %> + <%= f.input :description %> <%= render 'admin/education/programs/forms/input_with_inheritance', f: f, property: :registration %> <%= render 'admin/education/programs/forms/input_with_inheritance', f: f, property: :pricing %> <%= render 'admin/education/programs/forms/input_with_inheritance', f: f, property: :duration %> diff --git a/app/views/admin/education/programs/forms/_input_with_inheritance.html.erb b/app/views/admin/education/programs/forms/_input_with_inheritance.html.erb index 1553ecf8787c044259f170b646cb82d6e094a20c..50abd4dd0ce3ec6de5d3cab6ef1e4273e9e7c887 100644 --- a/app/views/admin/education/programs/forms/_input_with_inheritance.html.erb +++ b/app/views/admin/education/programs/forms/_input_with_inheritance.html.erb @@ -2,8 +2,6 @@ program = f.object best_prop_value = program.public_send("best_#{property}") best_prop_source = program.public_send("best_#{property}_source") -is_rich_text = best_prop_value.is_a?(ActionText::RichText) -as = is_rich_text ? :rich_text_area : :text id = "#{property}Collapse" %> <% if best_prop_source %> @@ -19,7 +17,7 @@ id = "#{property}Collapse" </a> </div> <div class="collapse" id="<%= id %>"> - <%= f.input property, as: as, label: false %> + <%= f.input property, as: :rich_text_area, label: false %> <div class="bg-light p-2 mt-n2"> <b><%= t 'admin.inheritance.sentence_html', link: link_to(best_prop_source, [:admin, best_prop_source]) %></b><br> <%= best_prop_value %> @@ -27,5 +25,5 @@ id = "#{property}Collapse" </div> </div> <% else %> - <%= f.input property, as: as %> + <%= f.input property, as: :rich_text_area %> <% end %>