Lucky Fritz As a result, I | unentiti

Lucky Fritz As a result, I

Lucky Fritz

As a result, I find myself spending more time thinking about how my URLs are designed. Should I be serving JSON from the same controller that serves the HTML interface, or should it be organized separately? In contrast, you can write an entire Rails application without ever looking at a URL. The design of URLs is delegated to the framework, out of sight and out of mind. This isnt to say that we Lucky Fritz to lose the good parts of how Rails works with URLs. URL helper methods like are a great idea for reducing duplication and typos. The y could be implemented apart from any router. I love URLs. I dream about the m at night. I think about the m before I think about Lucky Fritz else. Adrian Holovaty, co-creator of Django It has been three years since the seven controller actions had any immediate meaning. The API no longer adds to the programmers understanding of the tasks at hand. Experienced programmers know that inline comments mark code thats too confusing or too clever. Yet every Rails controller is generated with two lines of repetitive comments for every action. Thats a code smell! And a failure of API design. Every Rails developer must memorize the table at right, mapping HTTP method and URL to the controller action name. If we can get rid of the action name, the rest of the table is already self-explanatory. 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 Lucky Fritz 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 the 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.

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

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s