Last active
January 14, 2017 18:42
-
-
Save wintersolutions/b82adba8b32fcdf75fc4d0ed2455421d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class TrailblazerFoo::Create < Trailblazer::Operation | |
extend Contract::DSL | |
contract TrailblazerFoo::Contract::Create | |
step :log_params | |
step Model(TrailblazerFoo, :new) | |
step Contract::Build() | |
# TODO: actually get properties set on model | |
step Contract::Validate() | |
step Contract::Persist() | |
step :log_it | |
private | |
def log_params(options) | |
Rails.logger.info "create TrailblazerFoo with #{options['params']}" | |
end | |
def log_it(options) | |
Rails.logger.info "created TrailblazerFoo #{options['model'].id}" | |
end | |
end | |
class TrailblazerFoo::Contract::Create < Reform::Form | |
property :a_string | |
property :a_required_string | |
property :a_text | |
property :a_number | |
# TODO: why is this needed for form_for? | |
model :trailblazer_foo | |
# validates :a_required_string, presence: true | |
end | |
class TrailblazerFoosController < ApplicationController | |
def create | |
run TrailblazerFoo::Create do |result| | |
return redirect_to @model | |
end | |
# TODO: render cell | |
render html: concept('trailblazer_foo/cell', @model).(:new), layout: true | |
end | |
def destroy | |
end | |
def edit | |
# TODO: render cell | |
render html: concept('trailblazer_foo/cell').(:edit), layout: true | |
end | |
def index | |
trailblazer_foos = TrailblazerFoo.all | |
# TODO: render cell | |
render html: concept('trailblazer_foo/cell', trailblazer_foos).(:index), layout: true | |
end | |
def new | |
model = TrailblazerFoo::Contract::Create.new(TrailblazerFoo.new) | |
# TODO: render cell | |
render html: concept('trailblazer_foo/cell', model).(:new), layout: true | |
end | |
def show | |
run TrailblazerFoo::Show do |result| | |
# TODO: render cell | |
render html: concept('trailblazer_foo/cell', @model).(:show), layout: true | |
end | |
end | |
def update | |
end | |
end | |
# versions | |
# rails (5.0.1) | |
# reform (2.2.3) | |
# reform-rails | |
# trailblazer (2.0.0) | |
# trailblazer-rails (1.0.2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment