Add models needed to include images on ckeditor4
This commit is contained in:
committed by
Javi Martín
parent
dd1691ba8f
commit
424535c1ae
4
app/models/ckeditor/asset.rb
Normal file
4
app/models/ckeditor/asset.rb
Normal file
@@ -0,0 +1,4 @@
|
||||
class Ckeditor::Asset < ActiveRecord::Base
|
||||
include Ckeditor::Orm::ActiveRecord::AssetBase
|
||||
include Ckeditor::Backend::Paperclip
|
||||
end
|
||||
13
app/models/ckeditor/attachment_file.rb
Normal file
13
app/models/ckeditor/attachment_file.rb
Normal file
@@ -0,0 +1,13 @@
|
||||
class Ckeditor::AttachmentFile < Ckeditor::Asset
|
||||
has_attached_file :data,
|
||||
url: '/ckeditor_assets/attachments/:id/:filename',
|
||||
path: ':rails_root/public/ckeditor_assets/attachments/:id/:filename'
|
||||
|
||||
validates_attachment_presence :data
|
||||
validates_attachment_size :data, less_than: 100.megabytes
|
||||
do_not_validate_attachment_file_type :data
|
||||
|
||||
def url_thumb
|
||||
@url_thumb ||= Ckeditor::Utils.filethumb(filename)
|
||||
end
|
||||
end
|
||||
14
app/models/ckeditor/picture.rb
Normal file
14
app/models/ckeditor/picture.rb
Normal file
@@ -0,0 +1,14 @@
|
||||
class Ckeditor::Picture < Ckeditor::Asset
|
||||
has_attached_file :data,
|
||||
url: '/ckeditor_assets/pictures/:id/:style_:basename.:extension',
|
||||
path: ':rails_root/public/ckeditor_assets/pictures/:id/:style_:basename.:extension',
|
||||
styles: { content: '800>', thumb: '118x100#' }
|
||||
|
||||
validates_attachment_presence :data
|
||||
validates_attachment_size :data, less_than: 2.megabytes
|
||||
validates_attachment_content_type :data, content_type: /\Aimage/
|
||||
|
||||
def url_content
|
||||
url(:content)
|
||||
end
|
||||
end
|
||||
23
db/migrate/20180813141443_create_ckeditor_assets.rb
Normal file
23
db/migrate/20180813141443_create_ckeditor_assets.rb
Normal file
@@ -0,0 +1,23 @@
|
||||
class CreateCkeditorAssets < ActiveRecord::Migration
|
||||
def self.up
|
||||
create_table :ckeditor_assets do |t|
|
||||
t.string :data_file_name, null: false
|
||||
t.string :data_content_type
|
||||
t.integer :data_file_size
|
||||
t.string :data_fingerprint
|
||||
t.string :type, limit: 30
|
||||
|
||||
# Uncomment it to save images dimensions, if your need it
|
||||
t.integer :width
|
||||
t.integer :height
|
||||
|
||||
t.timestamps null: false
|
||||
end
|
||||
|
||||
add_index :ckeditor_assets, :type
|
||||
end
|
||||
|
||||
def self.down
|
||||
drop_table :ckeditor_assets
|
||||
end
|
||||
end
|
||||
28
db/schema.rb
28
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: 20180727140800) do
|
||||
ActiveRecord::Schema.define(version: 20180813141443) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
@@ -294,6 +294,20 @@ ActiveRecord::Schema.define(version: 20180727140800) do
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "ckeditor_assets", force: :cascade do |t|
|
||||
t.string "data_file_name", null: false
|
||||
t.string "data_content_type"
|
||||
t.integer "data_file_size"
|
||||
t.string "data_fingerprint"
|
||||
t.string "type", limit: 30
|
||||
t.integer "width"
|
||||
t.integer "height"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
add_index "ckeditor_assets", ["type"], name: "index_ckeditor_assets_on_type", using: :btree
|
||||
|
||||
create_table "comments", force: :cascade do |t|
|
||||
t.integer "commentable_id"
|
||||
t.string "commentable_type"
|
||||
@@ -1291,6 +1305,12 @@ ActiveRecord::Schema.define(version: 20180727140800) do
|
||||
add_index "votes", ["votable_id", "votable_type", "vote_scope"], name: "index_votes_on_votable_id_and_votable_type_and_vote_scope", using: :btree
|
||||
add_index "votes", ["voter_id", "voter_type", "vote_scope"], name: "index_votes_on_voter_id_and_voter_type_and_vote_scope", using: :btree
|
||||
|
||||
create_table "web_sections", force: :cascade do |t|
|
||||
t.text "name"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "widget_cards", force: :cascade do |t|
|
||||
t.string "title"
|
||||
t.text "description"
|
||||
@@ -1309,12 +1329,6 @@ ActiveRecord::Schema.define(version: 20180727140800) do
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "web_sections", force: :cascade do |t|
|
||||
t.text "name"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
add_foreign_key "administrators", "users"
|
||||
add_foreign_key "annotations", "legacy_legislations"
|
||||
add_foreign_key "annotations", "users"
|
||||
|
||||
Reference in New Issue
Block a user