I wrote this gem, https://github.com/NullVoxPopuli/skinny_controllers
which is influenced by Trailblazer, but less with some different opinions
here and there.

The main idea that it pulls out of trailblazer is operations and policies.

Operations are in `app/operations`
Policies are in `app/policies`

Operations control what data you are getting, and Policies control if you
are allowed to get it.

The goal is to have all the logic in ruby objects that don't require a
controller instance to run (i.e. avoiding put/get/post in your tests).

At the very minimum, you'd need

include SkinnyControllers::Diet
# and then in your action
render json: model
and the rest is implicit.

obviously, not everyone wants the same create / update / destroy
functionality, so that can all be configured:

here is an example of the `create` operation for the `EventsController`

module EventOperations
   class Create < SkinnyControllers::Operation::Base
     def run
       return unless allowed?
       # @model is used here, because the method `model` is memoized off
       @model = model_class.new(model_params)
       @model # or just `model`

`allowed?` is a special method that looks up the corresponding policy:

class EventPolicy < SkinnyControllers::Policy::Base
   # for the Create operation for the EventsController is matched to create?
in the policy
   # o / object here is the instance of the model trying to be created
   def create?(o = object)


I'm using this in a big side project I've been working on for event
registration. (Rails API + Ember)

example of operation specs:

example of policy specs:

You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/e2760ca2-b7e2-4690-827f-2a4410196ab1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 1 of 1 | next ›
Discussion Overview
grouprubyonrails-talk @
postedMar 8, '16 at 2:35p
activeMar 8, '16 at 2:35p

1 user in discussion

L. Preston Sego III: 1 post



site design / logo © 2022 Grokbase