<?xml version="1.0" encoding="UTF-8"?>
<blog-posts type="array">
  <blog-post>
    <blog-id type="integer">1</blog-id>
    <body>&lt;p&gt;In this post, we will see how to create a redirects log to mechanize library. Mechanize is following redirects, but what if I want to know which pages it visited? It is simple and easy to add redirects logs to mechanize.&lt;/p&gt;
&lt;p&gt;===================READ MORE===================&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://ruby-doc.org/stdlib/libdoc/net/http/rdoc/classes/Net/HTTP.html&quot;&gt;Net::HTTP&lt;/a&gt; is a library provides your program functions to access WWW documents. You can use it to send GET or POST requests. You can read the response and take an action depending on the response.&lt;/p&gt;
&lt;p&gt;The problem you may face is that if the response is 301 Redirect, then you should follow redirects yourself. The response body will be like the following:&lt;/p&gt;
&lt;pre name=&quot;code&quot; class=&quot;html&quot;&gt;
&amp;lt;html&amp;gt;&amp;lt;body&amp;gt;You are being &amp;lt;a href=&amp;quot;http://localhost:3000/user_sessions/new&amp;quot;&amp;gt;redirected&amp;lt;/a&amp;gt;.&amp;lt;/body&amp;gt;&amp;lt;/html&amp;gt;&lt;/pre&gt;
&lt;p&gt;A lot of work :(&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://mechanize.rubyforge.org/mechanize/&quot;&gt;Mechanize&lt;/a&gt;&amp;nbsp;library is used for automating interaction with websites. It&amp;nbsp;follows redirects, can follow links, and submit forms. You can also define the redirection_limits in case it will get in a too long redirections path.&lt;/p&gt;
&lt;p&gt;While I was using mechanize, I needed to know the pages it visited while redirects. Unfortunately it wasn't supported. However, it wasn't hard to add it.&lt;/p&gt;
&lt;p&gt;Now, lets add our sugar...&amp;nbsp;I will add it to mechanize version 0.9.3. We will play around &lt;strong&gt;lib/www/mechanize.rb&lt;/strong&gt; file&lt;/p&gt;
&lt;p&gt;First, lets add&amp;nbsp;redirects_log&amp;nbsp;attribute accessor around&amp;nbsp;&lt;strong&gt;line#85&amp;nbsp;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;
&lt;meta http-equiv=&quot;content-type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;&lt;/p&gt;
&lt;pre name=&quot;code&quot; class=&quot;ruby&quot;&gt;
attr_accessor :scheme_handlers
attr_accessor :redirection_limit
attr_accessor :redirects_log&lt;/pre&gt;
&lt;p&gt;And lets initialize this array in Mechanize &lt;strong&gt;initialize&lt;/strong&gt; method&lt;/p&gt;
&lt;pre name=&quot;code&quot; class=&quot;ruby&quot;&gt;
@redirects_log = []&lt;/pre&gt;
&lt;p&gt;Then modify around &lt;strong&gt;line#550&lt;/strong&gt; to add the visited page to our redirects_log array&lt;/p&gt;
&lt;pre name=&quot;code&quot; class=&quot;ruby&quot;&gt;
elsif res_klass &amp;lt;= Net::HTTPRedirection
  return page unless follow_redirect?
  log.info(&amp;quot;follow redirect to: #{ response['Location'] }&amp;quot;) if log
  @redirects_log &amp;lt;&amp;lt; response['Location']
  from_uri  = page.uri
&lt;/pre&gt;
&lt;p&gt;Finally, we can read the redirects logs&lt;/p&gt;
&lt;pre name=&quot;code&quot; class=&quot;ruby&quot;&gt;
agent.redirects_log&lt;/pre&gt;
&lt;p&gt;It is simple and easy. That is the honey of the open source community :)&lt;/p&gt;</body>
    <category-id type="integer">2</category-id>
    <comments-closed type="boolean" nil="true"></comments-closed>
    <created-at type="datetime">2010-03-07T06:44:32Z</created-at>
    <fck-created type="boolean">true</fck-created>
    <id type="integer">15</id>
    <is-complete type="boolean">true</is-complete>
    <posted-by-id type="integer">9</posted-by-id>
    <tag-string>Ruby, Rails,mechanize</tag-string>
    <title>Creating a Mechanize redirects log</title>
    <updated-at type="datetime">2010-03-07T11:44:32Z</updated-at>
    <url-identifier>2010/2/28/creating-a-mechanize-redirects-log</url-identifier>
  </blog-post>
  <blog-post>
    <blog-id type="integer">1</blog-id>
    <body>&lt;p&gt;Most of inventory applications have the same models and functionalities. Most of them should have shops, products, orders and line items. They need also to handle order payment status and fulfillment status. The products stock status is also a common requirement in most of them.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://www.shopify.com/&quot;&gt;Shopify&lt;/a&gt; handles all of that overhead and can do all of that for you. You won't need to handle this work every time. You can build your complete shop in just 2 minutes. Shop owners can create their shops, add products and product variants. Then shopify partners can create applications to integrate with the shop.&lt;/p&gt;
&lt;p&gt;
&lt;meta content=&quot;text/html; charset=utf-8&quot; http-equiv=&quot;content-type&quot; /&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://api.shopify.com/&quot;&gt;Shopify API&lt;/a&gt;&amp;nbsp;is an XML API that allows applications to integrate with Shopify via &lt;a href=&quot;http://en.wikipedia.org/wiki/Representational_State_Transfer&quot;&gt;REST&lt;/a&gt;ful actions using verbs (GET/POST/PUT/DELETE).&lt;/p&gt;
&lt;p&gt;===================READ MORE===================&lt;/p&gt;
&lt;p&gt;The Shopify&amp;nbsp;&lt;span style=&quot;vertical-align: top;&quot; class=&quot;caps&quot;&gt;API&lt;/span&gt;&amp;nbsp;lets you access a Shopify store from your own application. You can have many applications integrated with your shop store. It will be easy to integrate with the store through the XML REST convention. Shopify supports Rails applications to integrate with it. You will need to install&amp;nbsp;&lt;a href=&quot;http://github.com/shopify/shopify_app&quot;&gt;Shopify_app&lt;/a&gt;&amp;nbsp;plugin and&amp;nbsp;&lt;a href=&quot;http://github.com/Shopify/shopify_api&quot;&gt;ShopifyAPI&lt;/a&gt;&amp;nbsp;gem for integration.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://github.com/shopify/shopify_app&quot;&gt;Shopify app&lt;/a&gt; is a rails plugin that generates basic login controller for authentication.&amp;nbsp;&lt;span&gt;&lt;a href=&quot;http://github.com/Shopify/shopify_api&quot;&gt;ShopifyAPI&lt;/a&gt; is a lightweight gem for accessing the Shopify admin REST web services. ShopifyAPI can easily fetch orders and products using&amp;nbsp;
&lt;meta content=&quot;text/html; charset=utf-8&quot; http-equiv=&quot;content-type&quot;&gt;&lt;a href=&quot;http://api.rubyonrails.org/classes/ActiveResource/Base.html&quot;&gt;ActiveResource&lt;/a&gt;&amp;nbsp;as the following:   &lt;/meta&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;
&lt;meta content=&quot;text/html; charset=utf-8&quot; http-equiv=&quot;content-type&quot; /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;pre class=&quot;ruby&quot; name=&quot;code&quot;&gt;
products = ShopifyAPI::Product.find(:all)
orders   = ShopifyAPI::Order.find(:all)&lt;/pre&gt;
&lt;p&gt;You can also create, update or delete shopify resources using ActiveResource.&lt;/p&gt;
&lt;pre class=&quot;ruby&quot; name=&quot;code&quot;&gt;
#create product
product = ShopifyAPI::Product.create(:body =&amp;gt; &amp;quot;iphone&amp;quot;,
                                     :title =&amp;gt; &amp;quot;iphone by Apple&amp;quot;,
                                     :vendor =&amp;gt; &amp;quot;Burton&amp;quot;)

#update product title
product.title = &amp;quot;Apple iphone&amp;quot;
product.save

#delete product
product.destroy&lt;/pre&gt;
&lt;p&gt;
&lt;meta content=&quot;text/html; charset=utf-8&quot; http-equiv=&quot;content-type&quot; /&gt;&lt;/p&gt;
&lt;p&gt;This post just provides a fast introduction about shopify, shopify API, their shopify_app plugin and shopifyAPI gem. For more detailed information, check their official documentations.&lt;/p&gt;</body>
    <category-id type="integer">3</category-id>
    <comments-closed type="boolean" nil="true"></comments-closed>
    <created-at type="datetime">2010-03-02T07:33:00Z</created-at>
    <fck-created type="boolean">true</fck-created>
    <id type="integer">17</id>
    <is-complete type="boolean">true</is-complete>
    <posted-by-id type="integer">9</posted-by-id>
    <tag-string>ruby, rails, ActiveResource, shopify,rest</tag-string>
    <title>Shopify API overview</title>
    <updated-at type="datetime">2010-03-02T13:11:09Z</updated-at>
    <url-identifier>2010/3/2/shopify-api-overview</url-identifier>
  </blog-post>
  <blog-post>
    <blog-id type="integer">1</blog-id>
    <body>&lt;p&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin-left: 40px;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;strong&gt;Background&lt;br /&gt;
&lt;/strong&gt;&lt;/span&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;
Since the appearance of smart-phones, mobile development has been done in separate islands, with each island having it's own set of traditions and languages, &amp;quot;Objective-C&amp;quot;, &amp;quot;Java&amp;quot;, &amp;quot;.Net&amp;quot;......&lt;br /&gt;
So the demand for a cross platform technologies has increased, and indeed a solutions emerged, in this article I'm going to explore the main three technologies out there, &amp;quot;rhodes&amp;quot;, &amp;quot;PhoneGap&amp;quot;, &amp;quot;Titanium Appcelerator&amp;quot;.&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin-left: 40px;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;strong&gt;How it works?&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
Despite the fact that each smart phone speaks a totally different language than others, they share one great advantage, that's they all have a web browser, so they all understand HTML, CSS and Javascript.&lt;br /&gt;
So, this is the entry point for any technique targeting cross-platform, all of them are frameworks target the smart phone's web browser, but they differ in details, which we'll be discussing later.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;===================READ MORE===================&lt;/p&gt;
&lt;p style=&quot;margin-left: 40px;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;strong&gt;Advantages&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
- Write in familiar web development technologies, instead of learning about each framework.&lt;br /&gt;
- &amp;quot;Write once run every where&amp;quot; ( actually this not how things happens, most of the time, it's 'write once, debug every where' ).&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin-left: 40px;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;So, no steep learning curve for each platform, and no extra development time for porting to each platform, only a very small overhead for deployment on different platforms.&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin-left: 40px;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;strong&gt;Disadvantages&lt;/strong&gt; &lt;br /&gt;
&lt;br /&gt;
- More suitable for data oriented applications, but least effective in rich multimedia applications.&lt;br /&gt;
- No support for gaming.&lt;br /&gt;
- Lower performance profile compared with native technologies.&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;strong&gt;Technical Comparison&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;font-size: small;&quot;&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin-left: 40px;&quot;&gt;&lt;strong&gt;Development framework:&lt;/strong&gt;&lt;/p&gt;
&lt;p style=&quot;margin-left: 80px;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;strong&gt;Rhodes: &lt;/strong&gt;Hosts a Ruby on&amp;nbsp;Rails framework, which have views, controllers and models, but lighter weight than desktop framework, so, a light weight rails server runs under the hoods, and a html, javascript web pages is viewed inside a browser, so that this framework is much more easier for rails developer to grasp.&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;PhoneGap, Titanium:&amp;nbsp;&lt;/strong&gt;uses html, css and javascript, with application logic hosted inside a &amp;quot;WebView&amp;quot;&amp;nbsp;control, but don't mix this with normal web applications, as normal web applications don't have access to the native functions such as Camera, contacts, geolocation.....etc, but PhoneGap and Titanium compiles as normal application and hosts the code inside a WebView control so that they can access native functions through javascript bridges.&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin-left: 40px;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;strong&gt;Tools&lt;/strong&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin-left: 80px;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;strong&gt;Rhodes:&lt;/strong&gt; Comes with a gem that's used for building and packaging of your applications, and also have a web tool to accomplish these tasks.&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin-left: 80px;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;strong&gt;PhoneGap:&lt;/strong&gt; Depends on native development tools shipped with each framework SDK, xCode template for iPhone, Eclipse plugin for blackberry...&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin-left: 80px;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;strong&gt;Titanium: &lt;/strong&gt;Have a very pleasant and powerful IDE for creating, packaging and launching of your applications.&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin-left: 40px;&quot;&gt;&lt;strong&gt;&lt;span style=&quot;font-size: small;&quot;&gt;User experienc&lt;/span&gt;&lt;/strong&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;strong&gt;e&lt;/strong&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin-left: 80px;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;strong&gt;Rhodes: &lt;/strong&gt;Provides complete set of Native controls and styling through CSS to give the end user the same look 'n feel of native applications.&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin-left: 80px;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;strong&gt;PhoneGap: &lt;/strong&gt;Does not provide native controls, and lets it up to you to customize the look of your application.&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin-left: 80px;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;strong&gt;Titanium: &lt;/strong&gt;&lt;/span&gt;&lt;span style=&quot;font-size: small;&quot;&gt;Provides some native controls but have less support than Rhodes for native controls.&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin-left: 40px;&quot;&gt;&lt;strong&gt;&lt;span style=&quot;font-size: small;&quot;&gt;Supported Devices&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p style=&quot;margin-left: 80px;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;strong&gt;Rhodes: &lt;/strong&gt;Supports iPhone, BlackBerry, Android, &lt;/span&gt;Windows Mobile and Symbian.&lt;/p&gt;
&lt;p style=&quot;margin-left: 80px;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;strong&gt;PhoneGap: &lt;/strong&gt;Supports iPhone, BlackBerry and Android.&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin-left: 80px;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;strong&gt;Titanium: &lt;/strong&gt;Supports iPhone and Android, and there exist plans for support for other devices.&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin-left: 40px;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;strong&gt;License&lt;/strong&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin-left: 80px;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;strong&gt;Rhodes:&lt;/strong&gt; Commercial license for $500 per project.&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin-left: 80px;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;strong&gt;PhoneGap: &lt;/strong&gt;Open source and f&lt;/span&gt;&lt;span style=&quot;font-size: small;&quot;&gt;ree.&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin-left: 80px;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;strong&gt;Titanium:&lt;/strong&gt; Open source and free while in beta phase, but when released will be commercial.&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin-left: 80px;&quot;&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;Summary&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p style=&quot;margin-left: 40px;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;Cross-platform mobile frameworks, is only a trial to give the same functionality using the same code, when deployed on different platforms, but don't support advanced graphics features, as Gaming and extensive multimedia needs, and is the optimum choice when it comes to data oriented applications.&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;margin-left: 40px;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;Although PhoneGap is free and open source, it lacks the native look 'n feel supported by other frameworks, and Rhodes supports larger number of Devices, but Titanium have better support and tools than both.&lt;/span&gt;&lt;/p&gt;</body>
    <category-id type="integer">5</category-id>
    <comments-closed type="boolean" nil="true"></comments-closed>
    <created-at type="datetime">2010-02-10T11:11:10Z</created-at>
    <fck-created type="boolean">true</fck-created>
    <id type="integer">13</id>
    <is-complete type="boolean">true</is-complete>
    <posted-by-id type="integer">10</posted-by-id>
    <tag-string>mobile, iPhone, Android, Rhodes, PhoneGap,  Titanium Appcelerator</tag-string>
    <title>Cross-Plateform mobile applications, a dream becomes reality!</title>
    <updated-at type="datetime">2010-03-02T12:33:51Z</updated-at>
    <url-identifier>2010/2/10/cross-plateform-mobile-applications-a-dream-becomes-reality</url-identifier>
  </blog-post>
  <blog-post>
    <blog-id type="integer">1</blog-id>
    <body>&lt;p&gt;In previous rails versions, to prevent cross-site scripting, the h helper method must be called explicitly to escape the output to the response body. The &lt;em&gt;&lt;a href=&quot;http://github.com/nzkoz/rails_xss&quot;&gt;rails_xss&lt;/a&gt;&lt;/em&gt; plugin replaces the default ERB template handlers with eruibs, and switches the behavior to escape by default rather than requiring you to escape. This behavior is consistent with Rails 3.0. Install &lt;a href=&quot;http://github.com/nzkoz/rails_xss&quot;&gt;rails_xss &lt;/a&gt;using the following commands:&lt;/p&gt;
&lt;pre name=&quot;code&quot; class=&quot;ruby&quot;&gt;
sudo gem install erubis
ruby script/plugin install git://github.com/NZKoz/rails_xss.git&amp;nbsp;&lt;/pre&gt;
&lt;p&gt;===================READ MORE===================&lt;/p&gt;
&lt;p&gt;By default a string is considered unsafe and is escaped by rails. If you have your own helpers you should tell Rails that these strings are safe using html_safe! method. If you want to display the string as HTML code instead of escaping it you just call html_safe! on the string object. As an example before installing &lt;a href=&quot;http://github.com/nzkoz/rails_xss&quot;&gt;rails_xss&lt;/a&gt;:&lt;/p&gt;
&lt;pre class=&quot;ruby&quot; name=&quot;code&quot;&gt;
&amp;lt;%= &amp;quot;&amp;lt;h1&amp;gt;Hello, World!&amp;lt;/h1&amp;gt;&amp;quot; %&amp;gt; # not escaped
&amp;lt;%=h &amp;quot;&amp;lt;h1&amp;gt;Hello, World!&amp;lt;/h1&amp;gt;&amp;quot; %&amp;gt; # escaped&lt;/pre&gt;
&lt;p&gt;but after installing rails_xss by default a string is considered unsafe and will be escaped&lt;/p&gt;
&lt;pre name=&quot;code&quot; class=&quot;ruby&quot;&gt;
&amp;lt;%= &amp;quot;&amp;lt;h1&amp;gt;Hello, World!&amp;lt;/h1&amp;gt;&amp;quot; %&amp;gt; # escaped
&amp;lt;%= &amp;quot;&amp;lt;h1&amp;gt;Hello, World!&amp;lt;/h1&amp;gt;&amp;quot;.html_safe! %&amp;gt; # not escaped
&amp;lt;%= raw &amp;quot;&amp;lt;h1&amp;gt;Hello, World!&amp;lt;/h1&amp;gt;&amp;quot; %&amp;gt; # not escaped
&lt;/pre&gt;
&lt;p&gt;This helps in escaping any user-entered data in your application like comments. More information about rails_xss can be found at &lt;a href=&quot;http://github.com/nzkoz/rails_xss&quot;&gt;rails_xss&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;This escaping behavior will be painful if your application contains user-entered data, but from trusted sources like a blog. A blog contains many places that you don't want this behavior to be the default action. You will need to call html_safe! method in all the places you emit code to the view through strings. This behavior can be altered by adding a class method in ActiveRecord::Base class that will mark all the specified columns in a model as safe. This will make all blog models safe, and we won't need to call html_safe! every where in the views.&lt;/p&gt;
&lt;p&gt;In the config/initializers directory create &amp;quot;html_safe_attributes.rb&amp;quot; file; this file will be loaded every time you start the server. First we extend the ActiveRecord::Base class with the module that will contain our html_safe_attributes class method.&lt;/p&gt;
&lt;pre class=&quot;ruby&quot; name=&quot;code&quot;&gt;
class ActiveRecord::Base&lt;br /&gt;  def self.inherited_with_html_safe_attributes(klass)&lt;br /&gt;    inherited_without_html_safe_attributes(klass)&lt;br /&gt;    klass.extend(HTMLSafeAttributes)&lt;br /&gt;  end&lt;br /&gt;&lt;br /&gt;  class &amp;lt;&amp;lt;self&lt;br /&gt;    alias_method_chain :inherited, :html_safe_attributes&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;/pre&gt;
&lt;div&gt;&amp;nbsp;Then we write our HTMLSafeAttributes module:&lt;/div&gt;
&lt;pre class=&quot;ruby&quot; name=&quot;code&quot;&gt;
 module HTMLSafeAttributes&lt;br /&gt;  def html_safe_attributes(*attrs)&lt;br /&gt;    cols = attrs  &lt;br /&gt;    cols = columns.select { |col| col.type == :string || col.type == :text }.map(&amp;amp;:name) if attrs.first == :all&lt;br /&gt;    cols.each do |attr|&lt;br /&gt;      class_eval &amp;lt;&amp;lt;-STRING&lt;br /&gt;        def #{attr}&lt;br /&gt;         read_attribute(:#{attr}).html_safe!&lt;br /&gt;       end&lt;br /&gt;      STRING&lt;br /&gt;    end    &lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;class NilClass&lt;br /&gt;  def html_safe!&lt;br /&gt;    nil&lt;br /&gt;  end&lt;br /&gt;end&lt;/pre&gt;
&lt;p&gt;We enhanced the NilClass with html_safe! because a column value may be nil, and this will throw an exception in the read_attribute method. Now inside a blog model you specify your safe attributes, or you specify :all to mark all string in the model as safe.&lt;/p&gt;
&lt;pre class=&quot;ruby&quot; name=&quot;code&quot;&gt;
class BlogPost &amp;lt; ActiveRecord::Base&lt;br /&gt;  html_safe_attributes :all&lt;br /&gt;end&lt;/pre&gt;
&lt;p&gt;Any column whose type is string or text will be marked as safe.&lt;/p&gt;</body>
    <category-id type="integer">3</category-id>
    <comments-closed type="boolean" nil="true"></comments-closed>
    <created-at type="datetime">2010-02-03T16:16:59Z</created-at>
    <fck-created type="boolean">true</fck-created>
    <id type="integer">11</id>
    <is-complete type="boolean">true</is-complete>
    <posted-by-id type="integer">8</posted-by-id>
    <tag-string>rails, xss</tag-string>
    <title>Prevent cross-site scripting in rails-2.3.5 using rails_xss plugin</title>
    <updated-at type="datetime">2010-02-17T11:28:50Z</updated-at>
    <url-identifier>2010/2/3/prevent-cross-site-scripting-in-rails-2-3-5-using-rails_xss-plugin</url-identifier>
  </blog-post>
  <blog-post>
    <blog-id type="integer">1</blog-id>
    <body>&lt;p&gt;If you used page caching in a site that implements RESTful interface, you may face a problem. You could have multiple actions that share a single URL with different HTTP methods. For example, showing a document is served at /documents/1, while updating the same document is also at /documents/1. When I'm trying to update a document, the request is something like&lt;br /&gt;
&lt;br /&gt;
PUT /documents/1&lt;br /&gt;
&lt;br /&gt;
If your Apache is not well configured, it may respond with a cached file at /documents/1.html. This is wrong because this file should be served for GET requests only. In fact, POST, PUT and DELETE actions should never be cached because they change server state. Investigating in this issue, I found the following snippet at my .htaccess file.&lt;/p&gt;
&lt;p&gt;===================READ MORE===================&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Conditions for fastcgi&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; RewriteRule ^$ index.html [QSA]&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; RewriteRule ^([^.]+)$ $1.html [QSA]&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; RewriteCond %{REQUEST_FILENAME} !-f&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]&lt;br /&gt;
&lt;br /&gt;
To solve this problem I changed a line and added a new line to make it like this&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Conditions for fastcgi&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; RewriteRule ^$ index.html [QSA]&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; RewriteRule ^([^.]+)$ $1.html [QSA]&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; RewriteCond %{REQUEST_FILENAME} !-f&lt;strong&gt; &lt;span style=&quot;color: rgb(51, 153, 102);&quot;&gt;[OR]&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; RewriteCond %{THE_REQUEST} !^GET&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]&lt;br /&gt;
&lt;br /&gt;
This allows a request to served from file system only when the request is a GET request. This resolved the problem.&lt;/p&gt;</body>
    <category-id type="integer">3</category-id>
    <comments-closed type="boolean" nil="true"></comments-closed>
    <created-at type="datetime">2010-02-03T08:49:38Z</created-at>
    <fck-created type="boolean">true</fck-created>
    <id type="integer">10</id>
    <is-complete type="boolean">true</is-complete>
    <posted-by-id type="integer">5</posted-by-id>
    <tag-string>ruby, rails, apache, caching, htaccess</tag-string>
    <title>Skipping cache for POST actions in Apache</title>
    <updated-at type="datetime">2010-02-14T12:02:42Z</updated-at>
    <url-identifier>2010/2/3/skipping-cache-for-post-actions-in-apache</url-identifier>
  </blog-post>
</blog-posts>
