Add commentaire file uploader

This commit is contained in:
Mathieu Magnin 2017-10-30 16:07:02 +01:00
parent ff44fbe523
commit 5775901868
4 changed files with 23 additions and 1 deletions

View file

@ -1,9 +1,10 @@
class Commentaire < ActiveRecord::Base
belongs_to :dossier, touch: true
belongs_to :champ
belongs_to :piece_justificative
mount_uploader :file, CommentaireFileUploader
default_scope { order(created_at: :asc) }
scope :updated_since?, -> (date) { where('commentaires.updated_at > ?', date) }

View file

@ -0,0 +1,15 @@
class CommentaireFileUploader < BaseUploader
def root
File.join(Rails.root, 'public')
end
if Features.remote_storage
storage :fog
else
storage :file
end
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
end

View file

@ -0,0 +1,5 @@
class AddFileToCommentaires < ActiveRecord::Migration[5.0]
def change
add_column :commentaires, :file, :string
end
end

View file

@ -163,6 +163,7 @@ ActiveRecord::Schema.define(version: 20171117165748) do
t.datetime "updated_at", null: false
t.integer "piece_justificative_id"
t.integer "champ_id"
t.string "file"
t.index ["champ_id"], name: "index_commentaires_on_champ_id", using: :btree
t.index ["dossier_id"], name: "index_commentaires_on_dossier_id", using: :btree
end