diff --git a/app/models/legislation/question.rb b/app/models/legislation/question.rb index 7df8f67cf..c1dacd464 100644 --- a/app/models/legislation/question.rb +++ b/app/models/legislation/question.rb @@ -14,8 +14,14 @@ class Legislation::Question < ActiveRecord::Base validates :process, presence: true validates :title, presence: true + scope :sorted, -> { order('id ASC') } + def next_question_id - @next_question_id ||= process.questions.where("id > ?", id).order('id ASC').limit(1).pluck(:id).first + @next_question_id ||= process.questions.where("id > ?", id).sorted.limit(1).pluck(:id).first + end + + def first_question_id + @first_question_id ||= process.questions.sorted.limit(1).pluck(:id).first end def answer_for_user(user) diff --git a/app/views/legislation/questions/show.html.erb b/app/views/legislation/questions/show.html.erb index 6401359c0..808b5d331 100644 --- a/app/views/legislation/questions/show.html.erb +++ b/app/views/legislation/questions/show.html.erb @@ -16,6 +16,13 @@