<?xml version="1.0" encoding="UTF-8"?> <rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
><channel><title>Ruby on Rails Notes &#187; middleware</title> <atom:link href="http://railsnotes.com/tag/middleware/feed/" rel="self" type="application/rss+xml" /><link>http://railsnotes.com</link> <description>A code-heavy brain dump of stuff I come across working on Ruby on Rails projects including Models, ActiveRecord, Views, Controllers, RESTful rails, deployment, server stuff, etc.</description> <lastBuildDate>Sun, 29 Aug 2010 23:45:16 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.0.1</generator> <item><title>Rails &amp; Rack Middleware</title><link>http://railsnotes.com/104-rails-rack-middleware-screencast-notes/</link> <comments>http://railsnotes.com/104-rails-rack-middleware-screencast-notes/#comments</comments> <pubDate>Sun, 08 Mar 2009 23:57:56 +0000</pubDate> <dc:creator>Melvin Ram</dc:creator> <category><![CDATA[Other]]></category> <category><![CDATA[2.3]]></category> <category><![CDATA[middleware]]></category> <category><![CDATA[rack]]></category><guid
isPermaLink="false">http://railsnotes.wordpress.com/?p=104</guid> <description><![CDATA[Notes from RailsCasts Rack Middleware screencast Rack Middleware = filter which you can use to intercept a request and handle the behavior a little differently as it goes to and from the application Different between middleware &#38; metal = Metal is an endpoint &#38; middleware is designed to be more of a filter (changes behavior if [...]]]></description> <content:encoded><![CDATA[<p></p><p><strong>Notes from <a
href="http://railscasts.com/episodes/151-rack-middleware">RailsCasts </a><a
href="http://railscasts.com/episodes/151-rack-middleware">Rack Middleware screencast</a><a
href="http://railscasts.com/episodes/151-rack-middleware"></a></strong></p><ul><li>Rack Middleware = filter which you can use to intercept a request and handle the behavior a little differently as it goes to and from the application</li><li>Different between middleware &amp; metal = Metal is an endpoint &amp; middleware is designed to be more of a filter (changes behavior if it needs to.)</li><li>Goes into /lib directory as a .rb file?</li><li>All middleware takes a initialize(app) method. The app variable will hold the rails application</li><li>Adding a call(env) method will make it override rails. This needs to return a array with the same 3 elements as a metal.</li><li>to make rails use your middleware, add this to your environment.rb file inside the Initializer block: config.middleware.use &#8220;NameOfClass&#8221;</li><li>&#8216;rake middleware&#8217; will list out the middlewares used by your app</li><li>You&#8217;ll need to restart the server every time you create/change  a middleware</li><li>To execute your rails app from your middleware, just run .call on the rails app, ex: @app.call(env)</li><li>you can assign parts of the response from a rails app to variables using something like this:</li><li><span
style="font-family:Consolas;font-size:12px">status, headers, response = @app.call(env)</span></li><li>and then you can call return those back to the real response using something like this:</li><li><span
style="font-family:Consolas;font-size:12px">[status, headers, "Add stuff" + response.body]</span></li><li>response.body assumes that the app is a rails app. this is not best practice.</li><li>a better approach is to use [status, headers, self] together with def each(&amp;block)</li></ul> ]]></content:encoded> <wfw:commentRss>http://railsnotes.com/104-rails-rack-middleware-screencast-notes/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Rails Metal Screencast by RailsCasts</title><link>http://railsnotes.com/102-rails-metal-screencast-by-railscasts/</link> <comments>http://railsnotes.com/102-rails-metal-screencast-by-railscasts/#comments</comments> <pubDate>Sun, 08 Mar 2009 23:13:33 +0000</pubDate> <dc:creator>Melvin Ram</dc:creator> <category><![CDATA[Other]]></category> <category><![CDATA[2.3]]></category> <category><![CDATA[metal]]></category> <category><![CDATA[middleware]]></category> <category><![CDATA[rack]]></category><guid
isPermaLink="false">http://railsnotes.wordpress.com/?p=102</guid> <description><![CDATA[I just got done watching the screencast on Rails Metal by RailsCasts and I took some notes: Rails Casts Notes: #150 Rails Metal Bypass rails routing Simple request that happens frequently. to generate: ruby script/generate metal name_of_metal stored under app/metal/ in the generated code, the self.call(env) method should return an array. response code ex. 404 [...]]]></description> <content:encoded><![CDATA[<p></p><p>I just got done watching the <a
href="http://railscasts.com/episodes/150-rails-metal">screencast on Rails Metal by RailsCasts</a> and I took some notes:</p><p><strong>Rails Casts Notes: #150 Rails Metal</strong></p><ul><li>Bypass rails routing</li><li>Simple request that happens frequently.</li><li>to generate: ruby script/generate metal name_of_metal</li><li>stored under app/metal/</li><li>in the generated code, the self.call(env) method should return an array.<ol><li>response code ex. 404 or 200</li><li>hash of header options</li><li>Body content</li></ol></li><li>Won&#8217;t be recorded in log file since it bypass that as well.</li><li>When creating/changing a metal, you need to restart server</li><li>If there is a conflict between Rails routing and metal, metal wins because it gets the request before rails has had a chance to process it.</li><li>&#8220;ab -n 100 http://127.0.0.1:3000/processes/list&#8221; will run a benchmark that you can use to compare performance (just replace the url of page)</li></ul> ]]></content:encoded> <wfw:commentRss>http://railsnotes.com/102-rails-metal-screencast-by-railscasts/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk (user agent is rejected)
Database Caching 4/16 queries in 0.026 seconds using disk

Served from: railsnotes.com @ 2010-09-10 05:45:14 -->