Refactor globalize models code using a concern
I've chosen the name "Globalizable" because "Translatable" already existed.
This commit is contained in:
@@ -3,8 +3,7 @@ class AdminNotification < ActiveRecord::Base
|
||||
|
||||
translates :title, touch: true
|
||||
translates :body, touch: true
|
||||
globalize_accessors
|
||||
accepts_nested_attributes_for :translations, allow_destroy: true
|
||||
include Globalizable
|
||||
|
||||
translation_class.instance_eval do
|
||||
validates :title, presence: true
|
||||
|
||||
@@ -5,8 +5,7 @@ class Banner < ActiveRecord::Base
|
||||
|
||||
translates :title, touch: true
|
||||
translates :description, touch: true
|
||||
globalize_accessors
|
||||
accepts_nested_attributes_for :translations, allow_destroy: true
|
||||
include Globalizable
|
||||
|
||||
translation_class.instance_eval do
|
||||
validates :title, presence: true, length: { minimum: 2 }
|
||||
|
||||
@@ -8,8 +8,7 @@ class Budget
|
||||
accepted_content_types: [ "application/pdf" ]
|
||||
|
||||
translates :title, :description, touch: true
|
||||
globalize_accessors
|
||||
accepts_nested_attributes_for :translations, allow_destroy: true
|
||||
include Globalizable
|
||||
|
||||
belongs_to :investment
|
||||
belongs_to :status, class_name: 'Budget::Investment::Status'
|
||||
|
||||
8
app/models/concerns/globalizable.rb
Normal file
8
app/models/concerns/globalizable.rb
Normal file
@@ -0,0 +1,8 @@
|
||||
module Globalizable
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
globalize_accessors
|
||||
accepts_nested_attributes_for :translations, allow_destroy: true
|
||||
end
|
||||
end
|
||||
@@ -9,8 +9,7 @@ class Legislation::DraftVersion < ActiveRecord::Base
|
||||
translates :body, touch: true
|
||||
translates :body_html, touch: true
|
||||
translates :toc_html, touch: true
|
||||
globalize_accessors
|
||||
accepts_nested_attributes_for :translations, allow_destroy: true
|
||||
include Globalizable
|
||||
|
||||
belongs_to :process, class_name: 'Legislation::Process', foreign_key: 'legislation_process_id'
|
||||
has_many :annotations, class_name: 'Legislation::Annotation', foreign_key: 'legislation_draft_version_id', dependent: :destroy
|
||||
|
||||
@@ -13,8 +13,7 @@ class Legislation::Process < ActiveRecord::Base
|
||||
translates :summary, touch: true
|
||||
translates :description, touch: true
|
||||
translates :additional_info, touch: true
|
||||
globalize_accessors
|
||||
accepts_nested_attributes_for :translations, allow_destroy: true
|
||||
include Globalizable
|
||||
|
||||
PHASES_AND_PUBLICATIONS = %i(debate_phase allegations_phase proposals_phase draft_publication result_publication).freeze
|
||||
|
||||
|
||||
@@ -4,8 +4,7 @@ class Legislation::Question < ActiveRecord::Base
|
||||
include Notifiable
|
||||
|
||||
translates :title, touch: true
|
||||
globalize_accessors
|
||||
accepts_nested_attributes_for :translations, allow_destroy: true
|
||||
include Globalizable
|
||||
|
||||
belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id'
|
||||
belongs_to :process, class_name: 'Legislation::Process', foreign_key: 'legislation_process_id'
|
||||
|
||||
@@ -3,8 +3,7 @@ class Legislation::QuestionOption < ActiveRecord::Base
|
||||
include ActsAsParanoidAliases
|
||||
|
||||
translates :value, touch: true
|
||||
globalize_accessors
|
||||
accepts_nested_attributes_for :translations, allow_destroy: true
|
||||
include Globalizable
|
||||
|
||||
belongs_to :question, class_name: 'Legislation::Question', foreign_key: 'legislation_question_id', inverse_of: :question_options
|
||||
has_many :answers, class_name: 'Legislation::Answer', foreign_key: 'legislation_question_id', dependent: :destroy, inverse_of: :question
|
||||
|
||||
@@ -7,8 +7,7 @@ class Poll < ActiveRecord::Base
|
||||
translates :name, touch: true
|
||||
translates :summary, touch: true
|
||||
translates :description, touch: true
|
||||
globalize_accessors
|
||||
accepts_nested_attributes_for :translations, allow_destroy: true
|
||||
include Globalizable
|
||||
|
||||
RECOUNT_DURATION = 1.week
|
||||
|
||||
|
||||
@@ -6,8 +6,7 @@ class Poll::Question < ActiveRecord::Base
|
||||
include ActsAsParanoidAliases
|
||||
|
||||
translates :title, touch: true
|
||||
globalize_accessors
|
||||
accepts_nested_attributes_for :translations, allow_destroy: true
|
||||
include Globalizable
|
||||
|
||||
belongs_to :poll
|
||||
belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id'
|
||||
|
||||
@@ -4,8 +4,7 @@ class Poll::Question::Answer < ActiveRecord::Base
|
||||
|
||||
translates :title, touch: true
|
||||
translates :description, touch: true
|
||||
globalize_accessors
|
||||
accepts_nested_attributes_for :translations, allow_destroy: true
|
||||
include Globalizable
|
||||
|
||||
documentable max_documents_allowed: 3,
|
||||
max_file_size: 3.megabytes,
|
||||
|
||||
@@ -4,8 +4,7 @@ class SiteCustomization::Page < ActiveRecord::Base
|
||||
translates :title, touch: true
|
||||
translates :subtitle, touch: true
|
||||
translates :content, touch: true
|
||||
globalize_accessors
|
||||
accepts_nested_attributes_for :translations, allow_destroy: true
|
||||
include Globalizable
|
||||
|
||||
translation_class.instance_eval do
|
||||
validates :title, presence: true
|
||||
|
||||
@@ -8,8 +8,7 @@ class Widget::Card < ActiveRecord::Base
|
||||
translates :title, touch: true
|
||||
translates :description, touch: true
|
||||
translates :link_text, touch: true
|
||||
globalize_accessors
|
||||
accepts_nested_attributes_for :translations, allow_destroy: true
|
||||
include Globalizable
|
||||
|
||||
def self.header
|
||||
where(header: true)
|
||||
|
||||
Reference in New Issue
Block a user