Buzz Lightyear of Star Command The Adventure Begins

Buzz Lightyear of Star Command The Adventure Begins

So instead of going through this extra syntactical layer, lets deal directly with GET, POST, PUT, and DELETE. Suggestions follow. You can tell this is a great idea because its the way unit tests already work! Lets bring this syntax back to the controller and complete the API. Thinking in URLs helps you solve web-related problems in the right way. Exhibit A: If you deploy to a site whose view fragments are already cached in memcached, its likely that Rails asset caching view helpers will not be called and CSS bundles will not be generated. This whole problem is easily solved by using controllers to do what the y do best. Views and helpers should not generate URL based resources. Controllers should generate and cache assets, not view helpers. The re are many ways the controller API could be improved. Existing attempts have failed to achieve wide adoption because the y have tried to handle controllers, views, and models all at once Instead, I think a more limited, controller-only approach could work better. The first is already in wide use: Sinatra. Sinatra is arguably Buzz Lightyear of Star Command The Adventure Begins most widely replicated Ruby web framework, having inspired implementations in, Clojure, PHP, Scala, and many o the r languages. Part of the problem with writing a routing API is finding a way to describe multiple URLs in a single string. This problem is solved if you handle each URL on its own. The res no middle routing layer with arbitrary action names. HTTP method and URL are all you need but handlers can filter on the user agent or o the r header information. Thanks to Rack, Sinatra apps can be embedded in Rails applications. Or, Carl Lerche is writing a Rails 3 plugin that provides this syntax to Rails controllers Jamis Buck introduced an implementation of REST as a plugin four years ago. Yet unlike o the r areas of Rails that have seen massive improvements, Rails implementation of REST is basically the same as it was in Rails A halfway approach could combine elements of the Rails 3 router syntax with the class method style of configuration thats already familiar to Rails developers. Class method and HTTP-style methods. class ReportsController AppController beforefilter:au the nticate resource/api/v1/reports/:id get :collection do end get :member do id end put :member do id end end Variations on this syntax could easily accomodate nested resources, singleton resources, or o the r custom URL schemes. For several years, Rails has charged forward and defined new, innovative syntaxes for writing web applications. Its time for it to happen again. An improved syntax could get rid of stale controller actions, reduce confusion, reduce duplication, and improve the way we think about solving technical problems with web applications. I think the mere fact that a controller can be generated means that code shouldnt be the re. The res no intelligence in code that can be generated from a single resource name. you have a lot more room to raise the abstraction level and start getting declarative. I think making the controller more declarative is probably the end goal. Instead of the bulk of each action being an imperative mess, the controller can be heavier on the class-level configuration thats really proven itself in the model associations, scopes, plugin configuration, etc. class-level configuration directive in Merb/Rails 3 is a signal that controllers Buzz Lightyear of Star Command The Adventure Begins head in this direction. Thoughts and reactions? Reply to topfunky on Twitter, write a blog post of your own, or comment at Hacker News.

  1. No comments yet.
  1. No trackbacks yet.

Leave a comment