Created
June 11, 2015 02:44
-
-
Save macedo/01c2a54560d022401554 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 UsersController < ApplicationController | |
def create | |
respond User::Create do |user, format| | |
format.json { render status: :created, json: user.to_json } | |
end | |
end | |
end | |
class User < ActiveRecord::Base | |
has_secure_password | |
class Create < Trailblazer::Operation | |
include CRUD, Responder, Representer | |
model User, :create | |
contract do | |
property :email | |
property :password | |
property :password_confirmation | |
validates :email, presence: true, uniqueness: true | |
validates :password, length: { minimum: 20 } | |
end | |
def process(params) | |
validate(params) { contract.save } | |
end | |
class JSON < self | |
contract do | |
property :id | |
property :email | |
end | |
representer do | |
property :id | |
property :email | |
end | |
end | |
builds do |params| | |
JSON if params[:format] == :json | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment