<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>paulsturgess.co.uk articles</title>
    <link>http://www.paulsturgess.co.uk/archive</link>
    <description>paulsturgess.co.uk Ruby on Rails articles</description>
    <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/paulsturgesscouk" type="application/rss+xml" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /><item>
      <title>Ruby on Rails ActiveRecord::DangerousAttributeError</title>
      <link>http://www.paulsturgess.co.uk/articles/show/81-ruby-on-rails-activerecorddangerousattributeerror</link>
      <description>&lt;p&gt;If you get a Rails exception &lt;code&gt;ActiveRecord::DangerousAttributeError&lt;/code&gt; then you'll find it's because one of your attributes is using a name reserved by Active Record. Particularly when the attribute has the name of one of Active Record instance methods.&lt;/p&gt;

&lt;p&gt;For me I was using &lt;code&gt;owner_id&lt;/code&gt; as a custom foreign key. A quick change to &lt;code&gt;owned_by_id&lt;/code&gt; and all was fixed.&lt;/p&gt;</description>
      <guid>http://www.paulsturgess.co.uk/articles/show/81-ruby-on-rails-activerecorddangerousattributeerror</guid>
    </item>
    <item>
      <title>Undefined method `fragment_cache_store=' Ruby on Rails error</title>
      <link>http://www.paulsturgess.co.uk/articles/show/80-undefined-method-fragment_cache_store-ruby-on-rails-error</link>
      <description>&lt;p&gt;The variable &lt;code&gt;fragment_cache_store&lt;/code&gt; has now been replaced with just &lt;code&gt;cache_store&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;So in my case I changed:&lt;/p&gt;

&lt;pre&gt;&lt;code class="ruby"&gt;ActionController::Base.fragment_cache_store = :file_store, "#{RAILS_ROOT}/tmp/cache"&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;To:&lt;/p&gt;

&lt;pre&gt;&lt;code class="ruby"&gt;ActionController::Base.cache_store = :file_store, "#{RAILS_ROOT}/tmp/cache"&lt;/code&gt;&lt;/pre&gt;
</description>
      <guid>http://www.paulsturgess.co.uk/articles/show/80-undefined-method-fragment_cache_store-ruby-on-rails-error</guid>
    </item>
    <item>
      <title>Formatting a date string for database use in Ruby on Rails</title>
      <link>http://www.paulsturgess.co.uk/articles/show/79-formatting-a-date-string-for-database-use-in-ruby-on-rails</link>
      <description>&lt;p&gt;Sometimes you need to format a date / time correctly for database querying and sneaked into Rails 2.1 was a really helpful method for doing just that.&lt;/p&gt;

&lt;pre&gt;&lt;code class="ruby"&gt;Time.now.to_s(:db)&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;So the above would change Mon Apr 20 16:15:00 +0100 2009 to "2009-04-20 16:15:00".&lt;/p&gt;

</description>
      <guid>http://www.paulsturgess.co.uk/articles/show/79-formatting-a-date-string-for-database-use-in-ruby-on-rails</guid>
    </item>
    <item>
      <title>Using Cooliris with Ruby on Rails</title>
      <link>http://www.paulsturgess.co.uk/articles/show/78-using-cooliris-with-ruby-on-rails</link>
      <description>&lt;p&gt;&lt;a href="http://www.cooliris.com/"&gt;Cooliris&lt;/a&gt; (formally known as PicLens) is a great way of viewing images on the web, and it's really easy to make your Ruby on Rails app compatible. You just need to create an xml version of your page and Cooliris will read it like an rss feed.&lt;/p&gt;

&lt;p&gt;First create your Cooliris xml template in &lt;code&gt;/views/layouts/cooliris.rxml&lt;/code&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class="ruby"&gt;xml.instruct!

xml.rss "version" =&gt; "2.0", "xmlns:media" =&gt; "http://search.yahoo.com/mrss" do
 xml.channel do

   xml.title       @title
   xml.description @description
   xml.icon        "/images/your_logo.png"

   @images.each do |image|
     xml.item do
       xml.title            image.reference_number
       xml.link             images_url(:action =&gt; :view, :id =&gt; image)
       xml.guid             images_url(:action =&gt; :view, :id =&gt; image)
       xml.media:content, :url =&gt; image.authenticated_s3_url('public'), :type =&gt; "image/jpeg"
       xml.media:thumbnail, :url =&gt; image.authenticated_s3_url('public'), :type =&gt; "image/jpeg"
     end
   end

 end
end&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Obviously tweak the details where necessary, xml.link needs to point to the html page and the xml.media:content needs to be the path to the image itself.&lt;/p&gt;

&lt;p&gt;Then in your controller action you need to make sure you tell rails what to do when the xml version of the page is requested...&lt;/p&gt;

&lt;pre&gt;&lt;code class="ruby"&gt;images = Image.all

respond_to do |format|
  format.html do
    @cooliris = true
    @images = images.paginate :page =&gt; params[:page]
  end
  format.xml do
    @title = "My Images"
    @description = "Description of my images"
    @images = images
    render :template =&gt; "/layouts/cooliris", :layout =&gt; false
  end
end&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Note that the xml version loads all images whereas the html version paginates. This means Cooliris wont be limited to just showing the images on that corresponding html page.&lt;/p&gt;

&lt;p&gt;In the head of your layout template you need to add an auto discovery link that points to your xml page.&lt;/p&gt;

&lt;pre&gt;&lt;code class="ruby"&gt;&lt;% if @cooliris %&gt;
	&amp;lt;link rel=&amp;quot;alternate&amp;quot; href=&amp;quot;&amp;lt;%= request.request_uri + &amp;quot;.xml&amp;quot; %&amp;gt;&amp;quot; type=&amp;quot;application/rss xml&amp;quot; /&amp;gt;
&lt;% end %&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;I used an instance variable that is set in the controller action to ensure the link is only displayed when the Cooliris xml page is available.&lt;/p&gt;

&lt;p&gt;You are probably all done now, unless you aren't using restful routes. Basically you need to ensure you have a route that accepts the :format param so that Rails can serve the xml version of the page. Eg.&lt;/p&gt;

&lt;pre&gt;&lt;code class="ruby"&gt;map.connect '/images/:action/:id.:format', :controller =&gt; "images"&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;That's it!&lt;/p&gt;</description>
      <guid>http://www.paulsturgess.co.uk/articles/show/78-using-cooliris-with-ruby-on-rails</guid>
    </item>
    <item>
      <title>ActionView::TemplateError: uninitialized constant Err::Acts::Textiled::ClassMethods::RedCloth</title>
      <link>http://www.paulsturgess.co.uk/articles/show/77-actionviewtemplateerror-uninitialized-constant-erractstextiledclassmethodsredcloth</link>
      <description>&lt;p&gt;After I setup the acts_as_textiled plugin. I got the following error when I deployed to my production server.&lt;/p&gt; 

&lt;pre&gt;&lt;code class="ruby"&gt;ActionView::TemplateError: uninitialized constant Err::Acts::Textiled::ClassMethods::RedCloth &lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;At first I thought it was because the RedCloth gem was not installed, but it was. So I figured there must have been another error going on that was hidden away.&lt;/p&gt;

&lt;p&gt;I ssh'd onto the server and navigated to the directory where the app was stored and fired up the console.&lt;/p&gt;

&lt;pre&gt;&lt;code class="ruby"&gt;script/console production
require 'rubygems'
require 'RedCloth'
Could not find RubyGem echoe (&gt;= 0)&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The real problem was revealed, the echoe gem was missing.&lt;/p&gt;

&lt;pre&gt;&lt;code class="ruby"&gt;sudo gem install echoe&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Problem fixed. &lt;a href="http://blog.evanweaver.com/files/doc/fauna/echoe/classes/Echoe.html"&gt;Read all about echoe.&lt;/a&gt;&lt;/p&gt;</description>
      <guid>http://www.paulsturgess.co.uk/articles/show/77-actionviewtemplateerror-uninitialized-constant-erractstextiledclassmethodsredcloth</guid>
    </item>
    <item>
      <title>'load_missing_constant': uninitialized constant Inflector when upgrading to Ruby on Rails 2.2.2</title>
      <link>http://www.paulsturgess.co.uk/articles/show/76-load_missing_constant-uninitialized-constant-inflector-when-upgrading-to-ruby-on-rails-222</link>
      <description>&lt;p&gt;It would appear that the way the Inflector is used in Ruby on Rails 2.2.2 has changed. There are a few plugins that rely on it's old implementation, notably file_column.&lt;/p&gt;

&lt;p&gt;Upon trying to start my app I was getting...&lt;/p&gt;

&lt;pre&gt;&lt;code class="ruby"&gt;'load_missing_constant': uninitialized constant Inflector&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;To invoke the inflector you'll now need to use...&lt;/p&gt;

&lt;pre&gt;&lt;code class="ruby"&gt;ActiveSupport::Inflector&lt;/code&gt;&lt;/pre&gt;</description>
      <guid>http://www.paulsturgess.co.uk/articles/show/76-load_missing_constant-uninitialized-constant-inflector-when-upgrading-to-ruby-on-rails-222</guid>
    </item>
    <item>
      <title>Undefined method `cache_template_extensions=' when upgrading to Ruby on Rails 2.2.2</title>
      <link>http://www.paulsturgess.co.uk/articles/show/75-undefined-method-cache_template_extensions-when-upgrading-to-ruby-on-rails-222</link>
      <description>&lt;p&gt;After upgrading to Ruby on Rails 2.2.2 I was getting...&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;undefined method `cache_template_extensions='&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The simple fix was to remove it from my config/environments/development.rb file as it's now been deprecated.&lt;/p&gt;</description>
      <guid>http://www.paulsturgess.co.uk/articles/show/75-undefined-method-cache_template_extensions-when-upgrading-to-ruby-on-rails-222</guid>
    </item>
    <item>
      <title>Free Ruby on Rails security e-book</title>
      <link>http://www.paulsturgess.co.uk/articles/show/74-free-ruby-on-rails-security-e-book</link>
      <description>&lt;p&gt;The the ever so useful Ruby on Rails security blog, &lt;a href="http://www.rorsecurity.info"&gt;rorsecurity&lt;/a&gt;, has released a &lt;a href="http://www.rorsecurity.info/the-book/"&gt;free e-book&lt;/a&gt;.&lt;/p&gt;

</description>
      <guid>http://www.paulsturgess.co.uk/articles/show/74-free-ruby-on-rails-security-e-book</guid>
    </item>
    <item>
      <title>Hoptoad - Free ruby on rails exception catcher</title>
      <link>http://www.paulsturgess.co.uk/articles/show/73-hoptoad---free-ruby-on-rails-exception-catcher</link>
      <description>&lt;p&gt;I've been using the &lt;a href="http://github.com/rails/exception_notification/tree/master"&gt;exception_notification&lt;/a&gt; plugin for sometime now. It's been a life saver on many occassion, allowing me to be made aware of bugs at the earliest opportunity.&lt;/p&gt;

&lt;p&gt;However, there are occassions where you don't necessarily require multiple emails all notifying you of the same problem. This is where &lt;a href="http://www.hoptoadapp.com/welcome"&gt;Hoptoad&lt;/a&gt; comes in handy.&lt;/p&gt;

&lt;p&gt;It catches all your exceptions and holds them online, grouping them together and giving you a single notification.&lt;/p&gt;

&lt;p&gt;It's free and easy to 'drop in' as a replacement for exception notifier.&lt;/p&gt; </description>
      <guid>http://www.paulsturgess.co.uk/articles/show/73-hoptoad---free-ruby-on-rails-exception-catcher</guid>
    </item>
    <item>
      <title>Can't activate rubyforge</title>
      <link>http://www.paulsturgess.co.uk/articles/show/72-cant-activate-rubyforge</link>
      <description>&lt;p&gt;I just tried to start one of my rails apps and got...&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;Can't activate rubyforge (= 0.4.4, runtime), already activated rubyforge-1.0.0 (Gem::Exception)&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;I fixed it by uninstalling rubyforge completely and thus getting rid of version 0.4.4 and reinstalling to have just version 1.0.0.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;sudo gem uninstall -a rubyforge&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Confirming that I didn't mind the warning that 'one or more dependencies will not be met'.&lt;/p&gt;

&lt;p&gt;Then reinstalling it with...&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;sudo gem install rubyforge&lt;/code&gt;&lt;/pre&gt;
</description>
      <guid>http://www.paulsturgess.co.uk/articles/show/72-cant-activate-rubyforge</guid>
    </item>
  </channel>
</rss>
