Skip to content

Instantly share code, notes, and snippets.

@ychaker
Last active February 7, 2017 22:15
Show Gist options
  • Save ychaker/546df764e12769ce6758ff19e7f9f59b to your computer and use it in GitHub Desktop.
Save ychaker/546df764e12769ce6758ff19e7f9f59b to your computer and use it in GitHub Desktop.
Rails + Refile + Dropzone (8)
require 'representable/json'
class Doc::Create < Trailblazer::Operation
include Model
include Responder
include Representer
include Representer::Deserializer::Hash
include Dispatch
model Doc, :create
contract do
include Reform::Form::ModelReflections
property :task_id,
validates: { presence: true }
property :uploaded_at,
validates: { presence: true }
property :file,
validates: { presence: true, file: true }
end
callback :after_save, CreateDocCallback
def process params
validate params do |op|
op.save
callback!(:after_save)
end
end
private
def setup_params! params
@current_user = params[:current_user]
end
def setup_model! params
model.uploader = @current_user
model.uploaded_at = Time.now
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment