diff --git a/app/controllers/topics_controller.rb b/app/controllers/topics_controller.rb index 18e967e95..eaa699c37 100644 --- a/app/controllers/topics_controller.rb +++ b/app/controllers/topics_controller.rb @@ -44,7 +44,7 @@ class TopicsController < ApplicationController private def topic_params - params.require(:topic).permit(:title, :community_id) + params.require(:topic).permit(:title, :community_id, :description_as_comment) end def set_community diff --git a/app/models/topic.rb b/app/models/topic.rb index 6961e3f76..6da411aab 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -6,4 +6,12 @@ class Topic < ActiveRecord::Base belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id' has_many :comments, as: :commentable + + after_create :associate_comment + + private + + def associate_comment + Comment.create(commentable: self, user: self.author, body: self.description_as_comment) + end end diff --git a/app/views/topics/_form.html.erb b/app/views/topics/_form.html.erb index e0172219b..192e11fff 100644 --- a/app/views/topics/_form.html.erb +++ b/app/views/topics/_form.html.erb @@ -6,6 +6,8 @@
<%= f.label :title, t("topic.form.topic_title") %> <%= f.text_field :title %> + <%= f.label :description_as_comment, t("topic.form.topic_description_as_comment") %> + <%= f.text_area :description_as_comment, maxlength: Comment.body_max_length %>
diff --git a/db/migrate/20170807082243_create_topics.rb b/db/migrate/20170807082243_create_topics.rb index 047a7507c..1352751cc 100644 --- a/db/migrate/20170807082243_create_topics.rb +++ b/db/migrate/20170807082243_create_topics.rb @@ -2,6 +2,7 @@ class CreateTopics < ActiveRecord::Migration def change create_table :topics do |t| t.string :title, null: false + t.text :description_as_comment t.integer :author_id t.integer "comments_count", default: 0 t.references :community, index: true diff --git a/db/schema.rb b/db/schema.rb index 09047efe1..77b9d5d44 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -891,13 +891,14 @@ ActiveRecord::Schema.define(version: 20170807082243) do add_index "tags", ["spending_proposals_count"], name: "index_tags_on_spending_proposals_count", using: :btree create_table "topics", force: :cascade do |t| - t.string "title", null: false + t.string "title", null: false + t.text "description_as_comment" t.integer "author_id" - t.integer "comments_count", default: 0 + t.integer "comments_count", default: 0 t.integer "community_id" t.datetime "hidden_at" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end add_index "topics", ["community_id"], name: "index_topics_on_community_id", using: :btree