Last active
February 7, 2017 22:15
-
-
Save ychaker/546df764e12769ce6758ff19e7f9f59b to your computer and use it in GitHub Desktop.
Rails + Refile + Dropzone (8)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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