Merge branch 'master' into dashboard
This commit is contained in:
@@ -6,28 +6,26 @@ class Poll::Question < ActiveRecord::Base
|
||||
include ActsAsParanoidAliases
|
||||
|
||||
translates :title, touch: true
|
||||
globalize_accessors
|
||||
include Globalizable
|
||||
|
||||
belongs_to :poll
|
||||
belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id'
|
||||
belongs_to :author, -> { with_hidden }, class_name: "User", foreign_key: "author_id"
|
||||
|
||||
has_many :comments, as: :commentable
|
||||
has_many :answers, class_name: 'Poll::Answer'
|
||||
has_many :question_answers, -> { order 'given_order asc' }, class_name: 'Poll::Question::Answer'
|
||||
has_many :answers, class_name: "Poll::Answer"
|
||||
has_many :question_answers, -> { order "given_order asc" }, class_name: "Poll::Question::Answer"
|
||||
has_many :partial_results
|
||||
belongs_to :proposal
|
||||
|
||||
validates :title, presence: true
|
||||
validates_translation :title, presence: true, length: { minimum: 4 }
|
||||
validates :author, presence: true
|
||||
validates :poll_id, presence: true, if: Proc.new { |question| question.poll.nil? }
|
||||
|
||||
validates :title, length: { minimum: 4 }
|
||||
|
||||
accepts_nested_attributes_for :question_answers, reject_if: :all_blank, allow_destroy: true
|
||||
|
||||
scope :by_poll_id, ->(poll_id) { where(poll_id: poll_id) }
|
||||
|
||||
scope :sort_for_list, -> { order('poll_questions.proposal_id IS NULL', :created_at)}
|
||||
scope :sort_for_list, -> { order("poll_questions.proposal_id IS NULL", :created_at)}
|
||||
scope :for_render, -> { includes(:author, :proposal) }
|
||||
|
||||
def self.search(params)
|
||||
@@ -38,10 +36,10 @@ class Poll::Question < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def searchable_values
|
||||
{ title => 'A',
|
||||
proposal.try(:title) => 'A',
|
||||
author.username => 'C',
|
||||
author_visible_name => 'C' }
|
||||
{ title => "A",
|
||||
proposal.try(:title) => "A",
|
||||
author.username => "C",
|
||||
author_visible_name => "C" }
|
||||
end
|
||||
|
||||
def copy_attributes_from_proposal(proposal)
|
||||
@@ -49,7 +47,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(:"#{localized_attr_name_for(:title, Globalize.locale)}=", proposal.title)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user