From de135746173be92715201aa82021e9cdccbe4d2b Mon Sep 17 00:00:00 2001 From: Fernando Blat Date: Thu, 5 Jan 2017 12:31:20 +0100 Subject: [PATCH] Show link to the first question --- app/models/legislation/question.rb | 8 ++++- app/views/legislation/questions/show.html.erb | 7 +++++ config/locales/en.yml | 1 + config/locales/es.yml | 1 + spec/models/legislation/question_spec.rb | 29 ++++++++++++++++--- 5 files changed, 41 insertions(+), 5 deletions(-) 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 @@