Add comments translations
Co-Authored-By: Sebastia <sebastia.roig@gmail.com>
This commit is contained in:
committed by
voodoorai2000
parent
096a9f6bb8
commit
158af0217d
@@ -18,7 +18,10 @@ class Comment < ApplicationRecord
|
|||||||
|
|
||||||
attr_accessor :as_moderator, :as_administrator
|
attr_accessor :as_moderator, :as_administrator
|
||||||
|
|
||||||
validates :body, presence: true
|
translates :body, touch: true
|
||||||
|
include Globalizable
|
||||||
|
|
||||||
|
validates_translation :body, presence: true
|
||||||
validates :user, presence: true
|
validates :user, presence: true
|
||||||
|
|
||||||
validates :commentable_type, inclusion: { in: COMMENTABLE_TYPES }
|
validates :commentable_type, inclusion: { in: COMMENTABLE_TYPES }
|
||||||
|
|||||||
14
db/migrate/20181205102153_add_comments_translations.rb
Normal file
14
db/migrate/20181205102153_add_comments_translations.rb
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
class AddCommentsTranslations < ActiveRecord::Migration[4.2]
|
||||||
|
def self.up
|
||||||
|
Comment.create_translation_table!(
|
||||||
|
{
|
||||||
|
body: :text
|
||||||
|
},
|
||||||
|
{ migrate_data: true }
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.down
|
||||||
|
Comment.drop_translation_table!
|
||||||
|
end
|
||||||
|
end
|
||||||
10
db/schema.rb
10
db/schema.rb
@@ -415,6 +415,16 @@ ActiveRecord::Schema.define(version: 20190607160900) do
|
|||||||
t.index ["type"], name: "index_ckeditor_assets_on_type", using: :btree
|
t.index ["type"], name: "index_ckeditor_assets_on_type", using: :btree
|
||||||
end
|
end
|
||||||
|
|
||||||
|
create_table "comment_translations", force: :cascade do |t|
|
||||||
|
t.integer "comment_id", null: false
|
||||||
|
t.string "locale", null: false
|
||||||
|
t.datetime "created_at", null: false
|
||||||
|
t.datetime "updated_at", null: false
|
||||||
|
t.text "body"
|
||||||
|
t.index ["comment_id"], name: "index_comment_translations_on_comment_id", using: :btree
|
||||||
|
t.index ["locale"], name: "index_comment_translations_on_locale", using: :btree
|
||||||
|
end
|
||||||
|
|
||||||
create_table "comments", force: :cascade do |t|
|
create_table "comments", force: :cascade do |t|
|
||||||
t.integer "commentable_id"
|
t.integer "commentable_id"
|
||||||
t.string "commentable_type"
|
t.string "commentable_type"
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ describe Comment do
|
|||||||
let(:comment) { build(:comment) }
|
let(:comment) { build(:comment) }
|
||||||
|
|
||||||
it_behaves_like "has_public_author"
|
it_behaves_like "has_public_author"
|
||||||
|
it_behaves_like "globalizable", :comment
|
||||||
|
|
||||||
it "is valid" do
|
it "is valid" do
|
||||||
expect(comment).to be_valid
|
expect(comment).to be_valid
|
||||||
|
|||||||
Reference in New Issue
Block a user