adds question's show

This commit is contained in:
rgarcia
2016-11-16 19:41:29 +01:00
parent ac58f30498
commit 6fe965a9b8
5 changed files with 71 additions and 3 deletions

View File

@@ -3,6 +3,18 @@ class Polls::QuestionsController < ApplicationController
load_and_authorize_resource :poll load_and_authorize_resource :poll
load_and_authorize_resource :question, class: 'Poll::Question', through: :poll load_and_authorize_resource :question, class: 'Poll::Question', through: :poll
has_filters %w{opened expired incoming}
has_orders %w{most_voted newest oldest}, only: :show
def show
@commentable = @question.proposal.present? ? @question.proposal : @question
@comment_tree = CommentTree.new(@commentable, params[:page], @current_order)
set_comment_flags(@comment_tree.comments)
#@question_answer = @question.answers.where(author_id: current_user.try(:id)).first
@answers_by_question_id = {@question.id => params[:answer]}
end
def answer def answer
partial_result = @question.partial_results.find_or_initialize_by(author: current_user, partial_result = @question.partial_results.find_or_initialize_by(author: current_user,
amount: 1, amount: 1,

View File

@@ -7,6 +7,7 @@ module Abilities
can [:read, :map, :summary], Proposal can [:read, :map, :summary], Proposal
can :read, Comment can :read, Comment
can :read, Poll can :read, Poll
can :read, Poll::Question
can :read, SpendingProposal can :read, SpendingProposal
can :read, Legislation can :read, Legislation
can :read, User can :read, User

View File

@@ -0,0 +1,55 @@
<div class="expanded no-margin-top dark-heading">
<div class="row">
<div class="small-12 medium-9 column padding">
<%= render "shared/back_link" %>
<h1><%= @question.title %></h1>
<% if @question.proposal.present? %>
<div class="margin-bottom">
<%= link_to t('questions.show.original_proposal'), @question.proposal %>
</div>
<% end %>
<p><%= @question.summary %></p>
<ul class="tags">
<% @question.geozones.each do |g| %>
<li><%= g.name %></li>
<% end %>
</ul>
</div>
<div class="small-12 medium-3 column info">
<p>
<span class="title author"><%= t('questions.show.author') %></span><br>
<%= link_to @question.author.name, @question.author %>
</p>
<p>
<span class="title url"><%= t('questions.show.external_url') %></span><br>
<%# link_to @question.external_url, @question.external_url %>
</p>
</div>
</div>
</div>
<div class="row margin-top">
<div class="small-12 column text-center">
<h2><%= @question.question %></h2>
</div>
</div>
<div class="row margin-top text-center" id="<%= dom_id(@question) %>_answers">
<%= render "answers", question: @question %>
</div>
<div class="row margin-top">
<div class="small-12 medium-9 column">
<h3><%= t('questions.show.more_info') %></h3>
<%= @question.description %>
</div>
</div>
<%= render "comments" %>

View File

@@ -27,7 +27,7 @@
<% @answerable_questions.each do |question| %> <% @answerable_questions.each do |question| %>
<div id="<%= dom_id(question) %>"> <div id="<%= dom_id(question) %>">
<%= question.title %> <%= link_to question.title, poll_question_path(@poll, question) %>
<div class="row margin-top text-center" id="<%= dom_id(question) %>_answers"> <div class="row margin-top text-center" id="<%= dom_id(question) %>_answers">
<%= render 'polls/questions/answers', question: question %> <%= render 'polls/questions/answers', question: question %>
@@ -44,7 +44,7 @@
<% @non_answerable_questions.each do |question| %> <% @non_answerable_questions.each do |question| %>
<div id="<%= dom_id(question) %>"> <div id="<%= dom_id(question) %>">
<%= question.title %> <%= link_to question.title, poll_question_path(@poll, question) %>
<div class="row margin-top text-center" id="<%= dom_id(question) %>_answers"> <div class="row margin-top text-center" id="<%= dom_id(question) %>_answers">
<%= render 'polls/questions/answers', question: question %> <%= render 'polls/questions/answers', question: question %>

View File

@@ -84,7 +84,7 @@ Rails.application.routes.draw do
end end
resources :polls, only: [:show, :index] do resources :polls, only: [:show, :index] do
resources :questions, only: [], controller: 'polls/questions' do resources :questions, only: [:show], controller: 'polls/questions' do
post :answer, on: :member post :answer, on: :member
end end
end end