Add commentaire file uploader
This commit is contained in:
parent
ff44fbe523
commit
5775901868
4 changed files with 23 additions and 1 deletions
|
@ -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) }
|
||||
|
||||
|
|
15
app/uploaders/commentaire_file_uploader.rb
Normal file
15
app/uploaders/commentaire_file_uploader.rb
Normal 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
|
5
db/migrate/20171030150323_add_file_to_commentaires.rb
Normal file
5
db/migrate/20171030150323_add_file_to_commentaires.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
class AddFileToCommentaires < ActiveRecord::Migration[5.0]
|
||||
def change
|
||||
add_column :commentaires, :file, :string
|
||||
end
|
||||
end
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue