<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>David's Computer Stuff Journal: Tag rails</title>
    <link>http://journal.dedasys.com/articles/tag/rails</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description></description>
    <item>
      <title>Cache it all</title>
      <description>&lt;p&gt;I recently redid my personal web site, at &lt;a href="http://www.welton.it"&gt;welton.it&lt;/a&gt;.  Wanting to be quick about it, and make the look and feel a bit more uniform than it has been in the past, I hacked together some pages in Rails.  Despite this being sort of a "killing a fly with a bazooka" situation, I've been doing lots with Rails, so it was quick to use.  Here's the thing, though: Rails is definitely overkill, as the site is basically static.  I don't need to calculate anything or fetch stuff from a database - I just wanted a reasonably good template system, and I am quite comfortable with Rails these days.  &lt;/p&gt;

&lt;p&gt;But the idea of leaving Rails running for a static site was of course no good: I basically need to cache the entire thing, so that Rails is simply not involved.  How to do this as quick as possible (in between diaper changing and other baby duties!) ?   Ideally, it would be possible to introspect Rails in order to know exactly which pages are present, then cache those, and avoid Rails on the server entirely (just generate them locally and put them in subversion), but that proved to be fairly hacky, so I settled for this code, which simply caches all pages which comes across, when &lt;code&gt;caches_pages&lt;/code&gt; is placed in &lt;code&gt;application.rb&lt;/code&gt;:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;class CacheFileName
  include ActionController::Caching::Pages
  include ActionController::Caching::Pages::ClassMethods

  def cachedname(path)
    page_cache_file(path)
  end
end

def caches_pages()
  return unless perform_caching
  after_filter do |c|
    res = c.cache_page
    cfn = CacheFileName.new
    cf = Cachedfile.new :filename =&amp;gt; cfn.cachedname(c.request.path)
    cf.save!
  end
end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;It simply caches everything.  To be able to easily clear out the cache if there are any changes to the site, we record the changes in the Cachedfile model, which is defined like this:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;create_table "cachedfiles", :force =&amp;gt; true do |t|
  t.string   "filename"
  t.datetime "created_at"
  t.datetime "updated_at"
end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;with this model:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;class Cachedfile &amp;lt; ActiveRecord::Base

  def Cachedfile.clean_cache
    Cachedfile.find(:all).each do |cf|
      begin
        fn = ActionController::Base.page_cache_directory + cf.filename
        File.delete fn
      rescue =&amp;gt; e
        logger.error "Error deleting #{fn}: #{e.inspect}"
      ensure
        cf.destroy
      end
    end
  end

end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;which has a class method to go through and clean out all the cached files.  I call it manually from &lt;code&gt;./script/clean_cache&lt;/code&gt;:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;#!/usr/bin/env ruby

ENV['RAILS_ENV'] = ARGV.first || ENV['RAILS_ENV'] || 'development'

require File.dirname(__FILE__) + '/../config/boot'
require "#{RAILS_ROOT}/config/environment"
require 'console_app'

Cachedfile.clean_cache
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;It's not a beautiful system, but it gets the job done.&lt;/p&gt;</description>
      <pubDate>Fri, 13 Jun 2008 14:21:00 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:50f2dfc5-ae18-49a5-86cf-cdb2f5099f49</guid>
      <author>David N. Welton</author>
      <link>http://journal.dedasys.com/articles/2008/06/13/cache-it-all</link>
      <category>ruby</category>
      <category>rails</category>
      <trackback:ping>http://journal.dedasys.com/articles/trackback/1879</trackback:ping>
    </item>
    <item>
      <title>&amp;quot;Open Source&amp;quot; Akismet or Defensio?</title>
      <description>&lt;p&gt;I have a bad habit of getting caught up in side projects - I love to build stuff, and open see opportunities to engage in this hobby.  A site I've run for a while is the &lt;a href="http://www.leenooks.com"&gt;Linux Incompatibility List&lt;/a&gt;, which also led me to create my own Rails based wiki for it, &lt;a href="http://dedawiki.dedasys.com"&gt;DedaWiki&lt;/a&gt;, which is of course open source (and could use some more attention).&lt;/p&gt;

&lt;p&gt;However, things are getting badly on the spam front, and it's time to find a better solution than hacking at my own anti-spam code.  Two systems that look good are &lt;a href="http://akismet.com/"&gt;Akismet&lt;/a&gt;, which I use successfully for this journal, and &lt;a href="http://defensio.com/"&gt;Defensio&lt;/a&gt;.  However, being the impractical guy that I am, I am also curious if there are what we might call 'open source' efforts in this area. I'm not sure what that would look like, since there's probably strength in numbers, and a hosted solution is certainly easier.  Also, it seems the incentives in an arms race like anti-spam are in favor of the quick turnaround that a small, smart, dedicated team can provide.  Also... a bit of security through obscurity in an arms race type situation probably doesn't hurt, since there's often going to be a way around anything that's not locked down (and part of the value of a journal like this is in the comments), and letting people see exactly what numbers and ratios and metrics are being used is going to help the bad guys.&lt;/p&gt;

&lt;p&gt;Anyone able to point me to something that proves me wrong?&lt;/p&gt;</description>
      <pubDate>Fri, 18 Apr 2008 05:19:00 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:8480ee90-b47c-4323-8d21-519819e5179d</guid>
      <author>David N. Welton</author>
      <link>http://journal.dedasys.com/articles/2008/04/18/open-source-akismet-or-defensio</link>
      <category>rails</category>
      <category>spam</category>
      <trackback:ping>http://journal.dedasys.com/articles/trackback/1862</trackback:ping>
    </item>
    <item>
      <title>Rails and Hype</title>
      <description>&lt;p&gt;Yoav Shapira wonders about the "rails backlash":
&lt;a href="http://yoavs.blogspot.com/2008/02/railsshudder.html"&gt;http://yoavs.blogspot.com/2008/02/railsshudder.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I'm a big fan of Rails, and of course I realize that it has some flaws and is certainly not the optimal choice for all situations, but I don't buy into the bashing.&lt;/p&gt;

&lt;p&gt;Sure, Rails was hyped, but there is no way that it could have possible reached the level of popularity it has on hype alone.  We're not talking about multi-million dollar marketing budgets commanded by the likes of Sun or Microsoft, but about a video and some nice dressings by DHH and 37signals.  A small group like that just doesn't have the resources to push something like Rails as far as it's gone without some substance to back it up.&lt;/p&gt;

&lt;p&gt;Look at all the imitation.  People realize that the basic idea is good, and even though the basic idea is nothing phenomenal, it hadn't really been done before.  What is this idea?  Take a bunch of components, and good (if not always the absolute best) practices, and integrate them nicely.  Database, templating, testing, a clean application structure, ajax/javascript integration, with some code generation, all done with a language that's flexible enough to do all of the above pretty well.  All those things existed, but Rails did a great job of tying them all together.  And that's been imitated far and wide.  That seems to indicate that, even though the imitators may change and improve bits and pieces, they're quite smitten with the idea itself.  So much that they've dedicated a lot of time and effort to reproduce it.  That's quite a tribute.&lt;/p&gt;

&lt;p&gt;Look at the adoption.  Moving to a new language/platform is a big step, not one to be taken lightly, and for people with lots of existing code in some other language, perhaps simply not possible.  Hype will take things only so far, but Rails &lt;em&gt;has&lt;/em&gt; been taken up by a large number of people who certainly didn't do so because it was the safe, easy path to take.  Perhaps some of those people have found that Rails really wasn't for them, but that's pretty normal.  No one said it was perfect.  However, when you look at what it takes to make people jump ship from what they know, and are comfortable with, you realize that it really must have been that much better to make people go out on a limb.&lt;/p&gt;

&lt;p&gt;Furthermore, it's easy to point out the failings and drawbacks of something after the fact, but much more difficult to do creative, innovative work of your own.  Compounding that is the fact that criticizing others' work is often an easy and effective way of looking smart; there's an interesting study referenced here &lt;a href="http://bobsutton.typepad.com/my_weblog/2006/08/brilliant_but_c.html"&gt;http://bobsutton.typepad.com/my_weblog/2006/08/brilliant_but_c.html&lt;/a&gt; that talks about this effect.  &lt;/p&gt;

&lt;p&gt;It's something I've come to dislike over the years.  Our field is so new, so dynamic, and so immature, that it's usually pretty easy to take a look at something and say that it "sucks".  It is much harder to write something of your own and put it out there, knowing full well that lots of people who have never done much of anything will jump on it and bemoan its "copious failings".  That's not to say that it's impolite to criticize, but - do it constructively please.  Imagine that you were there in the same room, talking to the person who wrote the code in question.  You would still say you don't like it, but you'd probably be much more polite and helpful in your commentary.  I hope so, at least.&lt;/p&gt;</description>
      <pubDate>Sun, 03 Feb 2008 11:24:00 -0800</pubDate>
      <guid isPermaLink="false">urn:uuid:0a7250b8-35d5-42a4-8596-d2fc0c791592</guid>
      <author>David N. Welton</author>
      <link>http://journal.dedasys.com/articles/2008/02/03/rails-and-hype</link>
      <category>ruby</category>
      <category>rails</category>
      <trackback:ping>http://journal.dedasys.com/articles/trackback/1845</trackback:ping>
    </item>
    <item>
      <title>Interest in a simple open source newsletter system for Rails?</title>
      <description>&lt;p&gt;I'm putting together a very simple newsletter system for a client, based on Rails.  It's meant to handle around 1000 addresses, and be simple to use: you create a newsletter with fckeditor, look at it, then send it if everything looks good.  It also ads links so that people can unsubscribe, or subscribe from the site (with confirmation provided via a link in an email).&lt;/p&gt;

&lt;p&gt;It's not nearly as extensive as a lot of what I've seen out there in PHP, but I really needed something in Rails and didn't find anything that worked for me.  I'm considering open sourcing the code, but am only likely to do so if there is interest from people &lt;strong&gt;willing to work on the code&lt;/strong&gt;.  I'm just not in the mood to put code out there that just sits there.  If you are interested, email me and we can work something out.&lt;/p&gt;</description>
      <pubDate>Mon, 03 Dec 2007 03:25:00 -0800</pubDate>
      <guid isPermaLink="false">urn:uuid:638ac42d-cd11-41ab-a00a-e4539384c29b</guid>
      <author>David N. Welton</author>
      <link>http://journal.dedasys.com/articles/2007/12/03/interest-in-a-simple-open-source-newsletter-system-for-rails</link>
      <category>rails</category>
      <trackback:ping>http://journal.dedasys.com/articles/trackback/1828</trackback:ping>
    </item>
    <item>
      <title>One reason to think Rails is &amp;quot;all that&amp;quot;</title>
      <description>&lt;p&gt;The &lt;a href="http://www.welton.it/articles/programming_language_economics.html"&gt;economics of programming languages&lt;/a&gt; point to Rails being significantly better than what went before it.&lt;/p&gt;

&lt;p&gt;I got to thinking about this when reading a comment on a site I like to read, which said:&lt;/p&gt;

&lt;blockquote&gt;
    &lt;p&gt;Rails in itself is, to me, not that impressive. It does a lot of things right, but it does probably just as many wrong. Not the least of which is scaling.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It seems that these sorts of "after the fact" "I know better" comments are a dime a dozen in the world of programming discussions.  It's easy to come along after something's been built and puff yourself up by pointing to defects in existing systems and show that, therefore, by comparison, you're a clever fellow.&lt;/p&gt;

&lt;p&gt;That's not my point, though - what I wish to explain is that yes, Rails really was &lt;em&gt;that much&lt;/em&gt; better than what was around before it came onto the scene:&lt;/p&gt;

&lt;p&gt;"Switching costs" between languages are high.  Less so for really sharp programmers, but for the masses that use one or two languages, learning a new language, tools, deployment, etc... is a &lt;em&gt;big&lt;/em&gt; step to take, with potentially high risks.  Even most A-list programmers I know use a few languages at a time - it's simply easier if you're not tripping over your own feet by switching to a different system every day.  "Flow" is easier to attain when you're ensconced in the thinking of one language.  For companies, this effect is magnified, and switching to something new is not done lightly.&lt;/p&gt;

&lt;p&gt;Since companies &lt;em&gt;are&lt;/em&gt; beginning to explore Rails, successfully, I might add, you have to conclude that the big step into the unknown was worth it for some reason.  Especially considering that a number of other languages rushed to copy various nice aspects of Rails, lessening the need for users of those systems to consider taking the leap.&lt;/p&gt;

&lt;p&gt;Of course, that's not to say it's a perfect system, without reproach, or has no negative aspects, but in the spirit of honesty, and credit where credit is due, Rails really did move things a step forward, and the willingness of people to incur high switching costs to obtain its benefits is strong evidence of that.&lt;/p&gt;</description>
      <pubDate>Fri, 30 Nov 2007 01:56:00 -0800</pubDate>
      <guid isPermaLink="false">urn:uuid:ac663f99-7d03-47e2-8da9-8c12f2545d89</guid>
      <author>David N. Welton</author>
      <link>http://journal.dedasys.com/articles/2007/11/30/one-reason-to-think-rails-is-all-that</link>
      <category>ruby</category>
      <category>rails</category>
      <category>economics</category>
      <trackback:ping>http://journal.dedasys.com/articles/trackback/1827</trackback:ping>
    </item>
    <item>
      <title>Chartr - Plotr generation for Rails</title>
      <description>&lt;p&gt;I've been working on a &lt;a href="http://www.langpop.com"&gt;project&lt;/a&gt; that uses graphics created with &lt;a href="http://solutoire.com/plotr/"&gt;Plotr&lt;/a&gt;, and I wanted to automate that from Rails, so I created &lt;a href="http://chartr.rubyforge.org/"&gt;Chartr&lt;/a&gt;.  It's not very complete, but works well enough to create stuff like this:&lt;/p&gt;

&lt;hr/&gt;

&lt;p&gt;&lt;script src="http://chartr.rubyforge.org/prototype1_5_1_1.js" type="text/javascript"&gt;&lt;/script&gt;
    &lt;script src="http://chartr.rubyforge.org/excanvas.js" type="text/javascript"&gt;&lt;/script&gt;
    &lt;script src="http://chartr.rubyforge.org/plotr_uncompressed.js" type="text/javascript"&gt;&lt;/script&gt;&lt;/p&gt;

&lt;p&gt;&lt;div class="chart"&gt;
      &lt;canvas id="results_chart" height="300" width="500"&gt;&lt;/canvas&gt;
    &lt;/div&gt;&lt;/p&gt;

&lt;script type="text/javascript"&gt;
var dataset = {"Number/Decade": [[0, 1000], [1, 5000], [2, 20000], [3, 22000]]};
var options = {colorScheme: "#22aa22", legend: {position: {}}, axis: {x: {ticks: [{label: "1960", v: 0}, {label: "1970", v: 1}, {label: "1980", v: 2}, {label: "1990", v: 3}]}}, padding: {left: 100}, background: {}, stroke: {}, legend: {position: {left: '120px'}}};
var discvar = new Plotr.BarChart("results_chart", options);
discvar.addDataset(dataset);
discvar.render();
&lt;/script&gt;

&lt;hr/&gt;

&lt;p&gt;Help is more than welcome!  I think the API is still a bit clumsy, more chart types need adding, and there are other things that could probably be improved, but it does work.&lt;/p&gt;</description>
      <pubDate>Tue, 30 Oct 2007 08:15:00 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:ff569c5f-e2ef-48ff-b50a-899b8fb4650f</guid>
      <author>David N. Welton</author>
      <link>http://journal.dedasys.com/articles/2007/10/30/chartr-plotr-generation-for-rails</link>
      <category>ruby</category>
      <category>rails</category>
      <category>javascript</category>
      <trackback:ping>http://journal.dedasys.com/articles/trackback/1816</trackback:ping>
    </item>
  </channel>
</rss>
