diff --git a/app/controllers/admin/legislation/questions_controller.rb b/app/controllers/admin/legislation/questions_controller.rb index a643c39f5..9a1c3eb5b 100644 --- a/app/controllers/admin/legislation/questions_controller.rb +++ b/app/controllers/admin/legislation/questions_controller.rb @@ -7,6 +7,7 @@ class Admin::Legislation::QuestionsController < Admin::Legislation::BaseControll end def create + @question.author = current_user if @question.save redirect_to admin_legislation_process_questions_path else diff --git a/app/controllers/legislation/questions_controller.rb b/app/controllers/legislation/questions_controller.rb index 01653fca3..7114c98cb 100644 --- a/app/controllers/legislation/questions_controller.rb +++ b/app/controllers/legislation/questions_controller.rb @@ -2,6 +2,11 @@ class Legislation::QuestionsController < Legislation::BaseController load_and_authorize_resource :process load_and_authorize_resource :question, through: :process + has_orders %w{most_voted newest oldest}, only: :show + def show + @commentable = @question + @comment_tree = CommentTree.new(@commentable, params[:page], @current_order) + set_comment_flags(@comment_tree.comments) end end diff --git a/app/models/legislation/question.rb b/app/models/legislation/question.rb index c7c123437..2b779d1f8 100644 --- a/app/models/legislation/question.rb +++ b/app/models/legislation/question.rb @@ -1,8 +1,11 @@ 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' 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 accepts_nested_attributes_for :question_options, :reject_if => proc { |attributes| attributes[:value].blank? }, allow_destroy: true diff --git a/app/models/legislation/question_option.rb b/app/models/legislation/question_option.rb index 6d3654877..93bc20320 100644 --- a/app/models/legislation/question_option.rb +++ b/app/models/legislation/question_option.rb @@ -1,7 +1,8 @@ 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 :value, presence: true, uniqueness: { scope: :legislation_question_id } diff --git a/app/views/comments/_comment.html.erb b/app/views/comments/_comment.html.erb index 549b62862..deb6fa58d 100644 --- a/app/views/comments/_comment.html.erb +++ b/app/views/comments/_comment.html.erb @@ -1,6 +1,6 @@ <% cache [locale_and_user_status(comment), comment, commentable_cache_key(comment.commentable), comment.author, (@comment_flags[comment.id] if @comment_flags)] do %>
-
-
- -
-
- <%= t('.comments') %> -
-
+<%= render 'comments' %> diff --git a/config/locales/en.yml b/config/locales/en.yml index da1a1f6ea..cf076656f 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -269,7 +269,7 @@ en: other: "%{count} comments" debate: Debate show: - comments: COMMENTS + comments: Comments next_question: Next question share: Share share_twitter: Share on Twitter diff --git a/config/locales/es.yml b/config/locales/es.yml index bd5c748e0..0238645b6 100755 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -269,7 +269,7 @@ es: other: "%{count} comentarios" debate: Debate show: - comments: COMENTARIOS + comments: Comentarios next_question: Siguiente pregunta share: Compartir share_twitter: Compartir en Twitter diff --git a/db/migrate/20161222171716_add_comments_count_to_legislation_questions.rb b/db/migrate/20161222171716_add_comments_count_to_legislation_questions.rb new file mode 100644 index 000000000..e71a8879b --- /dev/null +++ b/db/migrate/20161222171716_add_comments_count_to_legislation_questions.rb @@ -0,0 +1,5 @@ +class AddCommentsCountToLegislationQuestions < ActiveRecord::Migration + def change + add_column :legislation_questions, :comments_count, :integer, default: 0 + end +end diff --git a/db/migrate/20161222180927_add_author_to_legislation_questions.rb b/db/migrate/20161222180927_add_author_to_legislation_questions.rb new file mode 100644 index 000000000..a06190045 --- /dev/null +++ b/db/migrate/20161222180927_add_author_to_legislation_questions.rb @@ -0,0 +1,5 @@ +class AddAuthorToLegislationQuestions < ActiveRecord::Migration + def change + add_column :legislation_questions, :author_id, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index f892724a5..96001434c 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # 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 enable_extension "plpgsql" @@ -293,6 +293,8 @@ ActiveRecord::Schema.define(version: 20161220120037) do t.datetime "hidden_at" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.integer "comments_count", default: 0 + t.integer "author_id" end add_index "legislation_questions", ["hidden_at"], name: "index_legislation_questions_on_hidden_at", using: :btree