mirror of
https://github.com/wahyd4/libr-2.git
synced 2026-08-09 05:15:53 +10:00
#7 Add thumbnail to post, system will auto parse the thumbnail
This commit is contained in:
@@ -5,5 +5,7 @@ class Post < ActiveRecord::Base
|
||||
has_many :favorites, as: :favoritable
|
||||
has_many :share_instances, as: :sharable
|
||||
|
||||
has_one :thumbnail
|
||||
|
||||
validates_presence_of :url, :type
|
||||
end
|
||||
|
||||
@@ -3,4 +3,6 @@ class Thumbnail < ActiveRecord::Base
|
||||
has_attached_file :file, :path => ":class/:attachment/:id/:basename.:extension"
|
||||
validates :file, :attachment_presence => true
|
||||
validates_attachment_content_type :file, :content_type => /\Aimage\/.*\Z/
|
||||
|
||||
belongs_to :post
|
||||
end
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
class PostSerializer < ActiveModel::Serializer
|
||||
|
||||
attributes :viewed_times, :url, :title, :type, :processed, :good_format, :created_at, :likes_count, :comments_count, :summary
|
||||
attributes :viewed_times, :url, :title, :type, :processed, :good_format, :created_at, :likes_count, :comments_count,
|
||||
:summary, :thumbnail
|
||||
|
||||
def thumbnail
|
||||
object.thumbnail.try(:file).try(:url)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -9,6 +9,9 @@ class ProcessPostWorker
|
||||
post.title = page.title
|
||||
post.summary = page.description
|
||||
post.processed = true
|
||||
if page.images.best.present?
|
||||
post.create_thumbnail file: URI.parse(page.images.best)
|
||||
end
|
||||
post.save
|
||||
end
|
||||
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddPostIdToThumbnail < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :thumbnails, :post_id, :integer
|
||||
end
|
||||
end
|
||||
+2
-1
@@ -11,7 +11,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20150914121114) do
|
||||
ActiveRecord::Schema.define(version: 20150914122528) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
@@ -141,6 +141,7 @@ ActiveRecord::Schema.define(version: 20150914121114) do
|
||||
t.integer "file_file_size"
|
||||
t.datetime "file_updated_at"
|
||||
t.text "file_meta"
|
||||
t.integer "post_id"
|
||||
end
|
||||
|
||||
create_table "users", force: :cascade do |t|
|
||||
|
||||
Reference in New Issue
Block a user