Update legislation questions translatable fields

This commit is contained in:
Javi Martín
2018-10-10 14:04:52 +02:00
parent 5bfc7ca2e3
commit 85701bd754
6 changed files with 46 additions and 29 deletions

View File

@@ -5,6 +5,7 @@ class Legislation::Question < ActiveRecord::Base
translates :title, touch: true
globalize_accessors
accepts_nested_attributes_for :translations, allow_destroy: true
belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id'
belongs_to :process, class_name: 'Legislation::Process', foreign_key: 'legislation_process_id'
@@ -17,7 +18,10 @@ class Legislation::Question < ActiveRecord::Base
accepts_nested_attributes_for :question_options, reject_if: proc { |attributes| attributes.all? { |k, v| v.blank? } }, allow_destroy: true
validates :process, presence: true
validates :title, presence: true
translation_class.instance_eval do
validates :title, presence: true
end
scope :sorted, -> { order('id ASC') }

View File

@@ -4,10 +4,14 @@ class Legislation::QuestionOption < ActiveRecord::Base
translates :value, touch: true
globalize_accessors
accepts_nested_attributes_for :translations, allow_destroy: true
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
validates :question, presence: true
validates :value, presence: true, uniqueness: { scope: :legislation_question_id }
translation_class.instance_eval do
validates :value, presence: true # TODO: add uniqueness again
end
end