Created
January 6, 2012 03:13
-
-
Save mattyoho/1568759 to your computer and use it in GitHub Desktop.
Random fever-dream sketch of possible alternative to ActionController
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
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