Comments in legislation question page
This commit is contained in:
@@ -7,6 +7,7 @@ class Admin::Legislation::QuestionsController < Admin::Legislation::BaseControll
|
|||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
|
@question.author = current_user
|
||||||
if @question.save
|
if @question.save
|
||||||
redirect_to admin_legislation_process_questions_path
|
redirect_to admin_legislation_process_questions_path
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -2,6 +2,11 @@ class Legislation::QuestionsController < Legislation::BaseController
|
|||||||
load_and_authorize_resource :process
|
load_and_authorize_resource :process
|
||||||
load_and_authorize_resource :question, through: :process
|
load_and_authorize_resource :question, through: :process
|
||||||
|
|
||||||
|
has_orders %w{most_voted newest oldest}, only: :show
|
||||||
|
|
||||||
def show
|
def show
|
||||||
|
@commentable = @question
|
||||||
|
@comment_tree = CommentTree.new(@commentable, params[:page], @current_order)
|
||||||
|
set_comment_flags(@comment_tree.comments)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
class Legislation::Question < ActiveRecord::Base
|
class Legislation::Question < ActiveRecord::Base
|
||||||
|
acts_as_paranoid column: :hidden_at
|
||||||
|
include ActsAsParanoidAliases
|
||||||
|
|
||||||
|
belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id'
|
||||||
belongs_to :process, class_name: 'Legislation::Process', foreign_key: 'legislation_process_id'
|
belongs_to :process, class_name: 'Legislation::Process', foreign_key: 'legislation_process_id'
|
||||||
|
|
||||||
has_many :question_options, class_name: 'Legislation::QuestionOption', foreign_key: 'legislation_question_id', dependent: :destroy, inverse_of: :question
|
has_many :question_options, class_name: 'Legislation::QuestionOption', foreign_key: 'legislation_question_id', dependent: :destroy, inverse_of: :question
|
||||||
# has_many :answers
|
|
||||||
has_many :comments, as: :commentable
|
has_many :comments, as: :commentable
|
||||||
|
|
||||||
accepts_nested_attributes_for :question_options, :reject_if => proc { |attributes| attributes[:value].blank? }, allow_destroy: true
|
accepts_nested_attributes_for :question_options, :reject_if => proc { |attributes| attributes[:value].blank? }, allow_destroy: true
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
class Legislation::QuestionOption < ActiveRecord::Base
|
class Legislation::QuestionOption < ActiveRecord::Base
|
||||||
belongs_to :question, class_name: 'Legislation::Question', foreign_key: 'legislation_question_id', inverse_of: :question_options
|
acts_as_paranoid column: :hidden_at
|
||||||
|
include ActsAsParanoidAliases
|
||||||
|
|
||||||
# has_many :answers
|
belongs_to :question, class_name: 'Legislation::Question', foreign_key: 'legislation_question_id', inverse_of: :question_options
|
||||||
|
|
||||||
validates :question, presence: true
|
validates :question, presence: true
|
||||||
validates :value, presence: true, uniqueness: { scope: :legislation_question_id }
|
validates :value, presence: true, uniqueness: { scope: :legislation_question_id }
|
||||||
|
|||||||
29
app/views/legislation/questions/_comments.html.erb
Normal file
29
app/views/legislation/questions/_comments.html.erb
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
<% cache [locale_and_user_status, @current_order, commentable_cache_key(@question), @comment_tree.comments, @comment_tree.comment_authors, @question.comments_count, @comment_flags] do %>
|
||||||
|
<div class="row comments">
|
||||||
|
<div id="comments" class="small-12 column">
|
||||||
|
<h3>
|
||||||
|
<%= t("legislation.questions.show.comments") %>
|
||||||
|
<span class="js-comments-count">(<%= @question.comments_count %>)</span>
|
||||||
|
</h3>
|
||||||
|
|
||||||
|
<%= render 'shared/wide_order_selector', i18n_namespace: "comments" %>
|
||||||
|
|
||||||
|
<% if user_signed_in? %>
|
||||||
|
<%= render 'comments/form', {commentable: @question, parent_id: nil, toggeable: false} %>
|
||||||
|
<% else %>
|
||||||
|
<br>
|
||||||
|
|
||||||
|
<div data-alert class="callout primary">
|
||||||
|
<%= t("debates.show.login_to_comment",
|
||||||
|
signin: link_to(t("votes.signin"), new_user_session_path),
|
||||||
|
signup: link_to(t("votes.signup"), new_user_registration_path)).html_safe %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<% @comment_tree.root_comments.each do |comment| %>
|
||||||
|
<%= render 'comments/comment', comment: comment %>
|
||||||
|
<% end %>
|
||||||
|
<%= paginate @comment_tree.root_comments %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
@@ -49,10 +49,4 @@
|
|||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<hr />
|
<%= render 'comments' %>
|
||||||
|
|
||||||
<div class="row">
|
|
||||||
<div class="small-12 column">
|
|
||||||
<%= t('.comments') %>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|||||||
@@ -269,7 +269,7 @@ en:
|
|||||||
other: "%{count} comments"
|
other: "%{count} comments"
|
||||||
debate: Debate
|
debate: Debate
|
||||||
show:
|
show:
|
||||||
comments: COMMENTS
|
comments: Comments
|
||||||
next_question: Next question
|
next_question: Next question
|
||||||
share: Share
|
share: Share
|
||||||
share_twitter: Share on Twitter
|
share_twitter: Share on Twitter
|
||||||
|
|||||||
@@ -269,7 +269,7 @@ es:
|
|||||||
other: "%{count} comentarios"
|
other: "%{count} comentarios"
|
||||||
debate: Debate
|
debate: Debate
|
||||||
show:
|
show:
|
||||||
comments: COMENTARIOS
|
comments: Comentarios
|
||||||
next_question: Siguiente pregunta
|
next_question: Siguiente pregunta
|
||||||
share: Compartir
|
share: Compartir
|
||||||
share_twitter: Compartir en Twitter
|
share_twitter: Compartir en Twitter
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
class AddCommentsCountToLegislationQuestions < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :legislation_questions, :comments_count, :integer, default: 0
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
class AddAuthorToLegislationQuestions < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :legislation_questions, :author_id, :integer
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -11,7 +11,7 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 20161220120037) do
|
ActiveRecord::Schema.define(version: 20161222180927) do
|
||||||
|
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
@@ -293,6 +293,8 @@ ActiveRecord::Schema.define(version: 20161220120037) do
|
|||||||
t.datetime "hidden_at"
|
t.datetime "hidden_at"
|
||||||
t.datetime "created_at", null: false
|
t.datetime "created_at", null: false
|
||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", null: false
|
||||||
|
t.integer "comments_count", default: 0
|
||||||
|
t.integer "author_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index "legislation_questions", ["hidden_at"], name: "index_legislation_questions_on_hidden_at", using: :btree
|
add_index "legislation_questions", ["hidden_at"], name: "index_legislation_questions_on_hidden_at", using: :btree
|
||||||
|
|||||||
Reference in New Issue
Block a user