From 3b8b86eb854f3b2b4694f405d48334311d74456f Mon Sep 17 00:00:00 2001 From: Stella Rouzi Date: Wed, 22 Apr 2015 18:55:51 +0300 Subject: [PATCH] show users per question --- app/controllers/admin/questions_controller.rb | 4 +++ app/models/registration.rb | 1 + .../admin/questions/_questions.html.haml | 1 + app/views/admin/questions/show.html.haml | 26 +++++++++++++++++++ 4 files changed, 32 insertions(+) create mode 100644 app/views/admin/questions/show.html.haml diff --git a/app/controllers/admin/questions_controller.rb b/app/controllers/admin/questions_controller.rb index c065c334..b55ff496 100644 --- a/app/controllers/admin/questions_controller.rb +++ b/app/controllers/admin/questions_controller.rb @@ -10,6 +10,10 @@ module Admin @new_question = @conference.questions.new end + def show + @registrations = @conference.registrations.joins(:qanswers).uniq + end + def new @question = Question.new(conference_id: @conference.id) authorize! :create, @question diff --git a/app/models/registration.rb b/app/models/registration.rb index 9f068317..e2bc78c4 100644 --- a/app/models/registration.rb +++ b/app/models/registration.rb @@ -25,6 +25,7 @@ class Registration < ActiveRecord::Base delegate :email, to: :user delegate :nickname, to: :user delegate :affiliation, to: :user + delegate :username, to: :user alias_attribute :other_needs, :other_special_needs diff --git a/app/views/admin/questions/_questions.html.haml b/app/views/admin/questions/_questions.html.haml index 124fa060..8417a0ef 100644 --- a/app/views/admin/questions/_questions.html.haml +++ b/app/views/admin/questions/_questions.html.haml @@ -19,6 +19,7 @@ %td .btn-group + = link_to 'Show', admin_conference_question_path(@conference.short_title, q), class: 'btn btn-success' = link_to 'Edit', edit_admin_conference_question_path(@conference.short_title, q), class: 'btn btn-primary', disabled: !(can? :update, q) = link_to 'Delete', admin_conference_question_path(@conference.short_title, q), diff --git a/app/views/admin/questions/show.html.haml b/app/views/admin/questions/show.html.haml new file mode 100644 index 00000000..0f01d41d --- /dev/null +++ b/app/views/admin/questions/show.html.haml @@ -0,0 +1,26 @@ +.container + .row + .col-md-12 + .page-header + %h1= @question.title + - @question.answers.each do |answer| + = answer.title + (#{answer.qanswers.find_by(question: @question).registrations.where(conference: @conference).count}) + + + .row + .col-md-12 + + %table.table.table-border.table-hover.datatable#question_users + %thead + %th Name + %th Username + %th Email + %th Answer + %tbody + - @registrations.each do |registration| + %tr + %td= registration.name + %td= registration.username + %td= registration.email + %td= registration.qanswers.find_by(question: @question).answer.title