Remove before validation callback

This was breaking nested poll_questions_answers when submitting
more than one new answer at a time.
This commit is contained in:
Senén Rodero Rodríguez
2018-12-27 18:06:13 +01:00
parent 7b2258aeb0
commit c73aae9663
6 changed files with 42 additions and 44 deletions

View File

@@ -17,8 +17,6 @@ class Poll::Question::Answer < ActiveRecord::Base
validates :title, presence: true
validates :given_order, presence: true, uniqueness: { scope: :question_id }
before_validation :set_order, on: :create
def description
self[:description].try :html_safe
end
@@ -29,10 +27,6 @@ class Poll::Question::Answer < ActiveRecord::Base
end
end
def set_order
self.given_order = self.class.last_position(question_id) + 1
end
def self.last_position(question_id)
where(question_id: question_id).maximum('given_order') || 0
end