Update poll questions translatable fields
We need to replace ".title=" by ".title_#{locale}=" in one place because
for some reason globalize builds a new translation record when using the
latter but it doesn't build one when using the former.
This commit is contained in:
@@ -7,6 +7,7 @@ class Poll::Question < ActiveRecord::Base
|
||||
|
||||
translates :title, touch: true
|
||||
globalize_accessors
|
||||
accepts_nested_attributes_for :translations, allow_destroy: true
|
||||
|
||||
belongs_to :poll
|
||||
belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id'
|
||||
@@ -17,12 +18,13 @@ class Poll::Question < ActiveRecord::Base
|
||||
has_many :partial_results
|
||||
belongs_to :proposal
|
||||
|
||||
validates :title, presence: true
|
||||
translation_class.instance_eval do
|
||||
validates :title, presence: true, length: { minimum: 4 }
|
||||
end
|
||||
|
||||
validates :author, presence: true
|
||||
validates :poll_id, presence: true
|
||||
|
||||
validates :title, length: { minimum: 4 }
|
||||
|
||||
scope :by_poll_id, ->(poll_id) { where(poll_id: poll_id) }
|
||||
|
||||
scope :sort_for_list, -> { order('poll_questions.proposal_id IS NULL', :created_at)}
|
||||
@@ -47,7 +49,7 @@ class Poll::Question < ActiveRecord::Base
|
||||
self.author = proposal.author
|
||||
self.author_visible_name = proposal.author.name
|
||||
self.proposal_id = proposal.id
|
||||
self.title = proposal.title
|
||||
send(:"title_#{Globalize.locale}=", proposal.title)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user