Skip to content

Instantly share code, notes, and snippets.

@mattyoho
Created January 6, 2012 03:13
Show Gist options
  • Save mattyoho/1568759 to your computer and use it in GitHub Desktop.
Save mattyoho/1568759 to your computer and use it in GitHub Desktop.
Random fever-dream sketch of possible alternative to ActionController
endpoints do
resources :widgets
end
# map "/widgets/:id", :to => WidgetEndpointFactory.new(:show), :as => :widget_path
# ...
# etc.
module ActionEndpoint::Endpoint
def view(object)
view = appropriate_view_for(object)
expose_to_template(view)
end
end
class WidgetCreateEndpoint
include ActionEndpoint::PostEndpoint
def action
widget = Widget.new(params[:widget])
widget.save # may succeed, may not; should handle appropriate status code,
# etc.; ideally by deferring to Rails functionality
view WidgetView.new(widget)
end
end
module ActionEndpoint::ActionView
# this is a friendly wrapper object that lets you
# easily use ActionController helpers such as #respond_to/#respond_with
include ActiveModel::Model #or whatever
end
class
# Need to inject a view method into the actual views that proxies
# to the "render"-ed/"return"-ed view object
#
# Can run through an over-arching ActionEndpointController instance
# that orchestrates behind the scenes in order to expose Rails functionality
# in order to evaluate/have a quick proof-of-concept
<div class="foo">
<%= view.widget.name %>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment