<?xml version="1.0" encoding="UTF-8"?>
<posts type="array">
  <post>
    <body>&lt;p&gt;As we head into the new year and a new decade I decided it was time for some changes around here.&lt;/p&gt;

&lt;h2&gt;Domain/Branding Change&lt;/h2&gt;
&lt;p&gt;My old blog/domain was GAPDesigns.com, which frankly made no sense at all. Not only do I not run a design firm, I am not a designer.&lt;/p&gt;

&lt;p&gt;I have owned AlanPeabody.com for a while, so this seemed the right time to start using it. In addition to representing that this is my personal blog better, it will also hopefully boost my Google presence. Specifically I am really hoping to have this blog be the number one result for searching Alan Peabody.&lt;/p&gt;

&lt;p&gt;Additionally one of my top priorities for this site was to provide a gateway to all my other online profiles. I think with the prominent display of my name and social icons that goal has been accomplished.&lt;/p&gt;

&lt;h2&gt;New Design&lt;/h2&gt;
&lt;p&gt;Change is good. While I am not a designer I do enjoy pushing myself and playing with design every once in a while. I think the change from a very light and open design to a darker, more constrained design is a good one.&lt;/p&gt;

&lt;p&gt;I also thought this was a good chance to play around with &lt;a href=&quot;http://typekit.com/&quot;&gt;TypeKit&lt;/a&gt; and get some experience with basic typography. I spent a lot of time playing with different fonts and I think the ones I settled on are quite readable. I also enjoyed using TypeKit, it is a very cool platform and I hope I have a chance to use it on a project in the future.&lt;/p&gt;

&lt;h2&gt;Software &amp; Hosting&lt;/h2&gt;
&lt;p&gt;This blog had previously been running on Radiant CMS, a great system. Unfortunately Radiant was giving me significant problems with Tags and Comments. My Radiant install was also a few versions out of date, and the extensions in use were not easy to upgrade.&lt;/p&gt;

&lt;p&gt;I have heard that &quot;Every Rails developer should write their own blog software.&quot; I guess it is about time I got around to it. It is a simple app, but the ability to completely customize it is really nice. Easy maintainability is also a boon.&lt;/p&gt;

&lt;p&gt;The last and maybe most enjoyable change has been the move away from a vps to using &lt;a href=&quot;http://heroku.com/&quot;&gt;Heroku&lt;/a&gt;. The easy of deployment and ability to scale is just fantastic. Not worrying about managing a VPS is worth the switch itself. I will definitely be recommending Heroku for all future projects.&lt;/p&gt;</body>
    <created-at type="datetime">2009-12-12T01:34:17Z</created-at>
    <id type="integer">1</id>
    <page-type>blog</page-type>
    <published type="datetime">2010-01-01T12:21:00Z</published>
    <slug>new-year-new-domain-new-design-new-brand-new-goals-new-software</slug>
    <title>New Year, New Domain, New Design, New Brand, New Goals, New Software</title>
    <updated-at type="datetime">2010-01-03T23:06:35Z</updated-at>
    <user-id type="integer" nil="true"></user-id>
  </post>
  <post>
    <body>&lt;p&gt;Just ran into this today, and did not find a documented solution out there.&lt;/p&gt;

&lt;p&gt;Lets jump into some code write away.&lt;/p&gt;

&lt;h3&gt;The Setup&lt;/h3&gt;

&lt;pre&gt;&lt;code&gt;
Class MyModel &amp;lt;&amp;lt; ActiveRecord::Base

  # This attribute is not mapped from the database,
  # but we want to validate it...
  attr_accessor :temp_attribute

  validates_numericality_of :temp_attribute

  before_save :do_something_with_attribute

  def do_something_with_attribute
    # do whatcha gotta do, aight?
  end

end
&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;The Problem&lt;/h3&gt;
&lt;p&gt;If you are on this post you probably got an error similar to: &lt;strong&gt;&lt;code&gt;undefined method `temp_attribute_before_type_cast'&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The reason you go this is because the &lt;code&gt;validates_numericality_of&lt;/code&gt; attempts to return the original value entered ( before column matching type casting). This original value is retrieved using the &lt;code&gt;*att*_before_type_case&lt;/code&gt; method.&lt;/p&gt;

&lt;p&gt;However our attribute never gets type casted and does not have the corresponding methods!&lt;/p&gt;

&lt;h3&gt;The Solution&lt;/h3&gt;
&lt;p&gt;Lets just define the &lt;code&gt;temp_attribute_before_type_cast&lt;/code&gt; method in our model.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
  def temp_attribute_before_type_cast
    self.temp_attribute.to_s
  end
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In my minimal testing this seems to work fine, as our attribute is never type cast prior to the &lt;code&gt;validates_numericality_of&lt;/code&gt; method.&lt;/p&gt;
</body>
    <created-at type="datetime">2010-01-02T07:05:31Z</created-at>
    <id type="integer">14</id>
    <page-type>blog</page-type>
    <published type="datetime">2009-10-18T23:04:00Z</published>
    <slug>activerecord-_before_type_cast-and-validates_numericality_of</slug>
    <title>ActiveRecord _before_type_cast and validates_numericality_of</title>
    <updated-at type="datetime">2010-01-02T07:05:31Z</updated-at>
    <user-id type="integer" nil="true"></user-id>
  </post>
  <post>
    <body>&lt;p&gt;Things change and move quickly in the Rails world. The technology you used 6 months ago is no longer the newest, shiniest toy in the box. Every 6 months or so I am going to start a journal of the technologies I am using and my thoughts on them. I hope it can provide a record for me to look back on and see how both the technology I use and my use and understanding of that technology has changed. I do try to stay current with the Rails world so I also hope this serves as a good representation of some of the current and popular technologies out there, with my own preferences of course.&lt;/p&gt;

&lt;p&gt;For side project I have going (to scratch my own itch) I am trying to do all new things. Some of the technologies are old, some are experimental or alpha; some are popular, others not. Without further ado... &lt;/p&gt;


&lt;h3&gt;Editor and Browser&lt;/h3&gt;

&lt;h4&gt;Chromium&lt;/h4&gt;
&lt;p&gt;Chromium is the open source project behind Google's super quick Chrome. The Chromium alpha build on Fedora 11 is lightning quick and easy on the memory. Now until now I have always preferred Firefox for the firebug plugin, but Chromium's built in tools are just as good for most cases. And it is fast as hell. Installing Chromium and keeping it up to date is almost as fast as the browser, thanks to a yum repository. Find out more at &lt;a href=&quot;http://digitizor.com/2009/06/25/how-to-install-chrome-browser-on-fedora-linux-that-works/&quot;&gt;Digitizor's How to Install Chrome on Fedora&lt;/a&gt;. Did I mention Chromium is fast?&lt;/p&gt;

&lt;h4&gt;gVim/Vim&lt;/h4&gt;
&lt;p&gt;Old to some, new to me. I figure working towards mastering Vim will make me a faster developer who can move between platforms more smoothly. It has been rough at first, but using gVim and just trying to look up things as I go has made learning not too difficult. I had some experience with vim before, so it isn't all new.&lt;/p&gt;
&lt;p&gt;A big thanks goes to Thoughtbot and their &lt;a href=&quot;http://robots.thoughtbot.com/post/166073596/intro-rails-vim&quot;&gt;Intro to Using Vim with Rails&lt;/a&gt;. If it wasn't for that post and screen cast I would not have given Vim another try. Extra props to Tim Pope for his excellent &lt;a href=&quot;http://rails.vim.tpope.net/&quot;&gt;rails.vim plugin&lt;/a&gt;.&lt;/p&gt;


&lt;h3&gt;Ruby And Rails&lt;/h3&gt;

&lt;h4&gt;Ruby 1.8.6&lt;/h4&gt;
&lt;p&gt;Not much to say here except looking forward to ruby 1.9, but it is still too early to as many gems are not supported.&lt;/p&gt;

&lt;h4&gt;Rails 2.3.3&lt;/h4&gt;
&lt;p&gt;As much as I would love to get on Edge Rails and be on Rails 3, the current lack of support of gems is really a deal breaker.&lt;/p&gt;


&lt;h3&gt;Markup&lt;/h3&gt;
&lt;p&gt;Yes markup get's it own section.&lt;/p&gt;

&lt;h4&gt;HTML 5&lt;/h4&gt;
&lt;p&gt;I am really looking forward to life with html5 and without IE. I know it won't happen until 2022 or something ridiculous, but here's hoping. I decided I really wanted to give html 5 a try before it started really getting supported, and so far so good (besides a little confusion with article vs section tags). I hope to work in some canvas elements as I go.&lt;/p&gt;

&lt;h4&gt;CSS 3&lt;/h4&gt;
&lt;p&gt;With CSS support in more of a mixed state then HTML 5 I am sure I will sneak in a few CSS 3 things, maybe multiple backgrounds. I am not much of a designer though, so we shall see.&lt;/p&gt;


&lt;h4&gt;Haml&lt;/h4&gt;
&lt;p&gt;Yep, using &lt;a href=&quot;http://haml-lang.com/&quot;&gt;HAML&lt;/a&gt; in html5 mode. I am still not sold on it as I already know and am comfortable writing html, but hey this is an experiment no? I do think it would be great for people who are not really used to writing valid html. Executing Ruby in haml is interesting, and maybe preferable to erb, but sometimes I find the lack of end tags surprising.&lt;/p&gt;

&lt;h4&gt;Sass&lt;/h4&gt;
&lt;p&gt;&lt;a href=&quot;http://sass-lang.com/&quot;&gt;Sass is awesome&lt;/a&gt;. Any misgivings I may or may not have about haml are completely irrelevant to how awesome sass is. Variables, mixins, compiling and minimizing. This is css done right. I do tend to not use some features too much, like avoiding excessive nesting, and I tend to still hit the &quot;You don't need that ; at the end of the line&quot; error a lot. It gets even better when you leverage....&lt;/p&gt;

&lt;h4&gt;...Compass&lt;/h4&gt;
&lt;p&gt;I think css frameworks are a joke. Blueprint and 960 totally ruin your beautifully semantic markup with presentation based class names and ids. It also adds a whole bunch of weight in styles you may or may not ever use.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://wiki.github.com/chriseppstein/compass&quot;&gt;Compass solves all of that&lt;/a&gt;, using your semantic class names you can use sass mixins to hook into that. While I still find some of the bigger frameworks slightly overkill, after all I want to customize things, one framework fit the bill.&lt;/p&gt;

&lt;h4&gt;Susy&lt;/h4&gt;
&lt;p&gt;&lt;a href=&quot;http://www.oddbird.net/susy/&quot;&gt;Susy is a very small grid based compass framework&lt;/a&gt; with just enough to get you going. It is fluid and flexible like css should be, and really easy to use. I had my layout pretty much done within minutes.&lt;/p&gt;


&lt;h3&gt;TDD/BDD&lt;/h3&gt;

&lt;h4&gt;Cucumber&lt;/h4&gt;
&lt;p&gt;Wrapping your head around &lt;a href=&quot;http://cukes.info/&quot;&gt;Cucumber&lt;/a&gt; is a bit tough at first, but I really like writing the feature and then making it pass. This is my first project using Cucumber and it took an awful lot of reading before I felt confident about using it. With Cucumber I feel better about my code and my app.&lt;/p&gt;

&lt;h4&gt;Webrat&lt;/h4&gt;
&lt;p&gt;This probably deserves it own section and thoughts, but I have only used it with cucumber so I really have not formed an opinion of webrat itself. I do hope to get to know this gem a bit better.&lt;/p&gt;

&lt;h4&gt;RSpec/RSpec Rails&lt;/h4&gt;
&lt;p&gt;I am using &lt;a href=&quot;http://rspec.info/&quot;&gt;RSpec&lt;/a&gt; for just model testing at the moment and replying on Cucumber for the controller and view tests. This may change as I get to more complex application logic.&lt;/p&gt;

&lt;h4&gt;Factory Girl&lt;/h4&gt;
&lt;p&gt;&lt;a href=&quot;http://www.thoughtbot.com/projects/factory_girl/&quot;&gt;Factory Girl&lt;/a&gt;'s factories are so much better then fixtures. I prefer to keep each factory in its own file in the &lt;code&gt;/spec/factories/&lt;/code&gt; directory.&lt;/p&gt;

&lt;h4&gt;Spork &amp; ZenTest&lt;/h4&gt;
&lt;p&gt;&lt;a href=&quot;http://spork.rubyforge.org/&quot;&gt;Spork&lt;/a&gt; and &lt;a href=&quot;http://www.zenspider.com/ZSS/Products/ZenTest/&quot;&gt;ZenTest's Autospec&lt;/a&gt; make BDD fun and easy. Now I just need to work on integrating it better with libnofity (Gnome's Growl).&lt;/p&gt;


&lt;h3&gt;Other Gems&lt;/h3&gt;

&lt;h4&gt;Authlogic&lt;/h4&gt;
&lt;p&gt;I'm giving &lt;a href=&quot;http://github.com/binarylogic/authlogic&quot;&gt;Authlogic&lt;/a&gt; a try for the first time after many projects using &lt;a href=&quot;http://github.com/technoweenie/restful-authentication&quot;&gt;Restful Authentication&lt;/a&gt;. I think having both to the tool belt will be beneficial. I particularly like not having a User model and using a custom named model more appropriate to the project.&lt;/p&gt;

&lt;h4&gt;Formtastic&lt;/h4&gt;
&lt;p&gt;Also new to me is &lt;a href=&quot;http://github.com/justinfrench/formtastic&quot;&gt;Formtastic&lt;/a&gt;. I have only used it a bit, but the ease of creating beautiful, semantic forms is amazing. I had to double check my views at first because I felt like they were missing so much! Love it so far and can't wait to really put it through the paces.&lt;/p&gt;

&lt;h4&gt;Will Paginate&lt;/h4&gt;
&lt;p&gt;&lt;a href=&quot;http://github.com/mislav/will_paginate&quot;&gt;THE pagination method&lt;/a&gt;. All that needs to be said has been.&lt;/p&gt;

&lt;h4&gt;Searchlogic&lt;/h4&gt;
&lt;p&gt;I had written my own version of a search library for active record, but I will be honest and tell you that &lt;a href=&quot;http://github.com/binarylogic/searchlogic&quot;&gt;Searchlogic&lt;/a&gt; is better.&lt;/p&gt;

&lt;h3&gt;Wrap up&lt;/h3&gt;

&lt;p&gt;And there it is, the technology stack I am currently choosing when developing a new project (or most of it, I am sure I forgot one or two). With the fast pace of Rails development I am very interested to see what I will still be using in six months and what will have changed or be new.&lt;/p&gt;
</body>
    <created-at type="datetime">2009-12-12T01:55:20Z</created-at>
    <id type="integer">2</id>
    <page-type>blog</page-type>
    <published type="datetime">2009-10-07T01:54:00Z</published>
    <slug>the-state-of-my-development-stack-issue-1</slug>
    <title>The State Of My Development Stack - Issue 1</title>
    <updated-at type="datetime">2010-01-02T07:03:35Z</updated-at>
    <user-id type="integer" nil="true"></user-id>
  </post>
  <post>
    <body>&lt;p&gt;All the commands needed to get a fully functional Rails development environment up an running on Fedora 11 as quickly as possible. Call it a cheat sheet if you will. This sets up postgre and sqlite3, NOT mysql. You may want to change that if you use mysql...&lt;/p&gt;

&lt;h3&gt;Install Ruby&lt;/h3&gt;

&lt;p&gt;Real Men don't use sudo.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
$ su -
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;All kinds of yummy ruby &amp; database goodness&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
# yum install ruby ruby-devel ruby-libs ruby-irb ruby-rdoc ruby-ri gcc cpp postgresql postgresql-server postgresql-devel pgadmin3 sqlite
&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;Install Ruby Gems&lt;/h3&gt;

&lt;p&gt;Gems from source is better then &lt;abbr title=&quot;yum + gems&quot;&gt;yems&lt;/abbr&gt;. (You may want to check for the most recent version, this is as of July 29th 2009.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
# wget http://rubyforge.org/frs/download.php/60718/rubygems-1.3.5.tgz
# tar -xzf rubygems-1.3.5.tgz 
# cd rubygems-1.3.5
# ruby setup.rb
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Set up some github.com as a gem source.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
# gem sources -a http://gems.github.com
&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;Use Gems to Install Rails etc&lt;/h3&gt;

&lt;p&gt;Install staples. (You may want to add Capistrano/Vlad here, but I don't use it...)&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
# gem install rake rails mongrel mislav-will_paginate postgres sqlite3-ruby
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Season to taste (BDD Stack + CMS).&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
# gem install rspec rspec-rails spork ZenTest autotest-rails thoughtbot-factory_girl radiant
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;You can then complete step 2 and 4 of my &lt;a href=&quot;http://gapdesigns.com/blog/2009/04/21/rails-and-postgresql-on-fedora-9/&quot;&gt;Rails and Postgre Guide&lt;/a&gt;&lt;/p&gt;.</body>
    <created-at type="datetime">2010-01-02T06:58:12Z</created-at>
    <id type="integer">12</id>
    <page-type>blog</page-type>
    <published type="datetime">2009-07-29T22:56:00Z</published>
    <slug>ruby-on-rails-up-and-running-on-fedora-11-quick-guide</slug>
    <title>Ruby on Rails up and running on Fedora 11 - Quick guide!</title>
    <updated-at type="datetime">2010-01-02T06:58:12Z</updated-at>
    <user-id type="integer" nil="true"></user-id>
  </post>
  <post>
    <body>&lt;p&gt;The recent Oracle-Sun acquisition on top of the mass exodus of MySQL developers from Sun has convienced my that my current project would benefit from a switch from MySQL to PostgreSQL. I was not to familiar with Postgres, so figuring out exactly how to install Postgres and migrate my Rails app to it was a little harder then it should have been. So, here is a quick and easy guide to Rails on Postgres and Fedora (9).&lt;/p&gt;

&lt;h3&gt;1) Install PostgreSQL&lt;/h3&gt;

&lt;p&gt;This is easy, just like MySQL (you may not need the development package...).&lt;/p&gt;
&lt;pre&gt;&lt;code lang=&quot;bash&quot;&gt;
$su -
#yum install -y postgresql-server postgresql postgresql-devel
&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;2) Configure PostgreSQL&lt;/h3&gt;

&lt;p&gt;Postgres is a bit different then MySQL at this point. Before you start the postgres service and set run levels you must assign the file space for the databases to use with the initdb command.&lt;/p&gt;
&lt;pre&gt;&lt;code lang=&quot;bash&quot;&gt;
# service postgresql initdb
# service postgresql start
# chkconfig postgresql on
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now we need to create databases and users. The first thing we need to do is log in as the postgres user.&lt;/p&gt;
&lt;pre&gt;&lt;code lang=&quot;bash&quot;&gt;
# su - postgres
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;As the postgres system user we need to create a db user. This first account will be a super user.&lt;/p&gt;
&lt;pre&gt;&lt;code lang=&quot;bash&quot;&gt;
$ creatuser -d -A -P superdbuserdude
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Then enter your password twice and hit y.&lt;/p&gt;

&lt;p&gt;Now we can create databases...&lt;p&gt;
&lt;pre&gt;&lt;code lang=&quot;bash&quot;&gt;
$ createdb testdb
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;...and drop them.&lt;/p&gt;
&lt;pre&gt;&lt;code lang=&quot;bash&quot;&gt;
$ dropdb testdb
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;However, we are still very limited on how we can access postgres. First log out of the postgres system user and back to root.&lt;/p&gt;
&lt;pre&gt;&lt;code lang=&quot;bash&quot;&gt;
$ exit
# whoami
root
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now we need to edit the &quot;host based access&quot; config file to allow username/password logins on the local machine. (As opposed to only allowing a login if the system username is the same as the database user name - the default setting.)&lt;/p&gt;

&lt;pre&gt;&lt;code lang=&quot;bash&quot;&gt;
# vi /var/lib/pgsql/data/pg_hba.conf
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;It would help to at least read this file a bit, but what we need to chang is down towards the bottom. Look for an uncommented line that reads:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
local   all         all                               ident sameuser
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Change it to: (press i to change to insert mode and then backspace and type)&lt;/p&gt; 
&lt;pre&gt;&lt;code&gt;
local   all         all                               trust
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Then save and exit. (press Esc then type :wq then press Enter)&lt;/p&gt;

&lt;p&gt;Now postgres is all set up. We are just missing one step..&lt;/p&gt;

&lt;h3&gt;3) Install Ruby-Postgres Bindings&lt;/h3&gt;

&lt;p&gt;As root install the Ruby postgres Gem. Some people recommend the ruby-postgres gem instead of the postgres gem so maybe you should use that, but at the time of this writing the postgres gem had been updated more recently and is what I used.&lt;/p&gt;
&lt;pre&gt;&lt;code lang=&quot;bash&quot;&gt;
# gem install postgres-ruby
--OR--
# gem install postgres
&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;4) Profit??&lt;/h3&gt;
&lt;p&gt;You can now create more users and databases as we did in step 2 and create rails applications on postgres.&lt;/p&gt;
&lt;pre&gt;&lt;code lang=&quot;bash&quot;&gt;
$ rails testing_pg --database=postgresql
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;You will have to set up a user and database for the app and edit the config/database.yml file to reflect your set up.&lt;/p&gt;

&lt;p&gt;Enjoy PostgreSQL!&lt;/p&gt;</body>
    <created-at type="datetime">2010-01-02T06:59:53Z</created-at>
    <id type="integer">13</id>
    <page-type>blog</page-type>
    <published type="datetime">2009-04-21T22:58:00Z</published>
    <slug>rails-and-postgresql-on-fedora-9</slug>
    <title>Rails and PostgreSQL on Fedora 9</title>
    <updated-at type="datetime">2010-01-02T06:59:53Z</updated-at>
    <user-id type="integer" nil="true"></user-id>
  </post>
  <post>
    <body>&lt;p&gt;Just wanted to post this up really quickly because it caught me off guard. Capitalizing the D in document will work in Firefox in Linux and Safari on OSX, but not in Chrome on Windows(Vista) or IE6 or IE7.&lt;/p&gt;

&lt;pre&gt;&lt;code lang=&quot;javascript&quot;&gt;
$(document).ready(function(){
  //Good
});

$(Document).ready(function(){
  //Bad
});
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;No, I do not know why I ever capitalized it.&lt;/p&gt;

&lt;p&gt;That is all... Hope this helps someone. :)&lt;/p</body>
    <created-at type="datetime">2010-01-02T06:54:12Z</created-at>
    <id type="integer">11</id>
    <page-type>blog</page-type>
    <published type="datetime">2009-04-02T22:52:00Z</published>
    <slug>jquery-document-ready-iechrome-issue---captilization-matters</slug>
    <title>jQuery $(document).ready IE/Chrome Issue - Captilization Matters!</title>
    <updated-at type="datetime">2010-02-04T14:16:26Z</updated-at>
    <user-id type="integer" nil="true"></user-id>
  </post>
  <post>
    <body>&lt;p&gt;On a recent project I was doing a lot of Ajax page loads for a &quot;dashboard&quot; type page. It was a case where I felt an Ajax approach was required. It was an internal project, so requiring JavaScript was not a problem.&lt;/p&gt;
&lt;p&gt;However, I did have one major issue with the system. The back button was broken. This was a huge usability issue and needed to be resolved.&lt;/p&gt;
&lt;h2&gt;jQuery History Plugin&lt;/h2&gt;
&lt;p&gt;In the &lt;a href=&quot;http://plugins.jquery.com/&quot;&gt;jQuery plugin index&lt;/a&gt; I found a &lt;a href=&quot;http://plugins.jquery.com/project/history&quot;&gt;history plugin&lt;/a&gt; that seemed promising, but was lacking much documentation. I also played with a few other plugins and found this one the best suited to my purpose.&lt;/p&gt;
&lt;h2&gt;The Rails App&lt;/h2&gt;
&lt;p&gt;My application was a simple dashboard based around a parent object. The parent object had many associated models in one to many relationships. The dashboard needed the ability to display the parent object data in conjunction with lists of associated models. The data was displayed in a &quot;window&quot; with a title bar. For now all data is displayed in the same window, however tabs are on the to-do list.&lt;/p&gt;
&lt;p&gt;To handle the actually CRUD of each model I simply created REST controller for each. The dashboard was then in its own namespace.&lt;/p&gt;
&lt;h2&gt;Browser history and complex Rails routes.&lt;/h2&gt;
&lt;p&gt;The basic principle of faking a browser history when using ajax, is using the hash portion of the url to simulate clicking links. (Because clicking a link to a new anchor does not actually reload the page.) This means if you load a page http://localhost:3000/dashboard/#view the url corresponding to the hash #view is loaded. If you then click on a &lt;code&gt;&amp;lt;a href=&quot;#edit&quot;&amp;gt;link&amp;lt;/a&amp;gt;&lt;/code&gt; the corresponding url is loaded.&lt;p&gt;
&lt;h3&gt;The Problem&lt;/h3&gt;
&lt;p&gt;This is a simple enough theory, but becomes complicated when you add two problems.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;For Graceful Degradation you want the actually url of the resource, not an arbitrary hash, as the url in the link.&lt;/li&gt;
&lt;li&gt;Maintaining a javascript array of hashes and url would quickly become a messy headache.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;The Solution&lt;/h3&gt;
&lt;p&gt;In a moment of genius (one of many I assure you) I realized there is an easy way. I will walk through the resulting code function by function.&lt;/p&gt;

&lt;pre&gt;&lt;code lang=&quot;javascript&quot;&gt;
standardContentLoad = function(data,status){
  $('#details-content').html(data);
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This method simply loads the html returned by the ajax request (if successful) into the correct div and calls the ajaxifyLinks function which we will look at in a bit.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
setTitle = function(title){
  $('#details-header h2').html(title);
  document.title = title;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This method simply sets the &quot;window&quot; title and the document title at the same time. The document title change is important for usability, as it shows up in the browsers history menu.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
ajaxPath = new Array();
initPathsFromLinks = function(){
  $(&quot;a.remote&quot;).each(function(){
    if (this.rel){
      ajaxPath[this.rel.replace(/\s/,'-')] = new Array(this.href,this.title);
    }
  });
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This method is the real genius, it assumes that all ajax links will be on the non-dynamic part of the page. In my case there is a menu consisting of dynamic links. It finds every link with a class of remote, and adds a record to the associative array ajaxPath. The array key is the hash (minus the sharp-#) and has two items in the array, the url of the page and the title.&lt;/p&gt;
&lt;p&gt;To get all this info is quite easy. The link itself actually links to the url. The title comes from the link's title attribute, and the hash is stored in the rel attribute (with spaces instead of dashes), though some may consider that a gross misuse of the rel attribute. Basically you end up with a bunch of links looking like this: &lt;code&gt;&amp;lt;a href=&quot;/parent/1/edit&quot; title=&quot;Edit [Parent Name]&quot; rel=&quot;edit parent&quot; &amp;gt;Edit&amp;lt;/a&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
pageLoad = function(hash) {
  if(hash) {
    $.get(ajaxPath[hash][0], function(data){ standardContentLoad(data,&quot;success&quot;); });
    setTitle(ajaxPath[hash][1]);
  }
  else {
    //default path
    //Load your default page, or do nothing at all.
  }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This function is key to the history plugin. It is called everytime the page is loaded or the url changes. If it gets a hash/anchor passed in it find the associated url and title from the associative array generated in the initPathsFromLinks function and sends a get request. The data is then passed to the content loading function standardContentLoad.&lt;/p&gt;
&lt;p&gt;If no hash is specified you can do whatever you would like, including loading a specific page via ajax.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
ajaxifyLinks = function(){
  $(&quot;a.remote&quot;).click(function(){
    var hash = this.rel;
    hash = hash.replace(/\s/,'-');
    
    $.history.load(hash);
    return false;
  });
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This function is basically my Hijax function. It adds a listener to the click event of any links with class remote. These links will then be loaded via the history plugin's &lt;code&gt;$.history.load()&lt;/code&gt; function from the hash stored in the links rel tag. The return false then ensures teh links default behavior(loading a new page) is not fired.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
$(Document).ready(function(){
  initPathsFromLinks();
  $.history.init(pageLoad);
  ajaxifyLinks();
});
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The final bit of code simply fires everything off. First the path array is created, then we fire of the history plugin's &lt;code&gt;$.history.init()&lt;/code&gt; function with a call to our pageLoad function. Then we just make sure all remote links are being listened to and will not behave as a standard link.&lt;/p&gt;

&lt;h2&gt;Disclosure&lt;/h2&gt;
&lt;p&gt;This is a fairly simple example extracted from a more complicated project, &lt;abbr title=&quot;Your Mileage May Vary&quot;&gt;YMMV&lt;/abbr&gt;. Please Script Responsibly ;-)&lt;/p&gt;




</body>
    <created-at type="datetime">2010-01-02T06:51:44Z</created-at>
    <id type="integer">10</id>
    <page-type>blog</page-type>
    <published type="datetime">2009-02-03T22:50:00Z</published>
    <slug>using-the-jquery-history-plugin-with-rails</slug>
    <title>Using the jQuery history plugin with Rails</title>
    <updated-at type="datetime">2010-01-02T06:51:44Z</updated-at>
    <user-id type="integer" nil="true"></user-id>
  </post>
  <post>
    <body>&lt;p&gt;In today's modern day web apps, the polish Ajax can provide is essential. However, you need to ensure that your application degrades nicely for those who don't have, or are not using, JavaScript; including some mobile users.&lt;/p&gt;

&lt;p&gt;When requesting html from a scaffold generated REST action in a Rails app with an application layout you end up with a layout inside of a layout. Not what you wanted.&lt;/p&gt;

&lt;p&gt;However, Rails provides the &lt;code&gt;request.xhr?&lt;/code&gt; method which returns true or false. This actually just checks to see if the &lt;i&gt;X-Requested-With&lt;/i&gt; request header was set to &lt;i&gt;XMLHttpRequest&lt;/i&gt; by Prototype/JQuery.&lt;/p&gt;

&lt;p&gt;So now you can go sticking &lt;code&gt;render :layout =&gt; false if request.xhr?&lt;/code&gt; on all your actions, but that's not very DRY is it?&lt;/p&gt;

&lt;p&gt;After quite a few google searches I found this &lt;a href=&quot;http://jamiedubs.com/always-render-rails-views-without-the-full-layout-when-using-ajax-degradable-javascript&quot;&gt;useful override of the render method&lt;/a&gt; on &lt;a href=&quot;http://jamiedubs.com/&quot;&gt;Jamie Wilkinson's blog&lt;/a&gt;. Simply add it to your application controller and it will not render the layout on ajax requests.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
def render(*args)
  args.first[:layout] = false if request.xhr? and args.first[:layout].nil?
  super
end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Unfortunately this didn't quite work for me. I was still having problems with the edit action, I believe this was because it was the only action with out a respond to block. After a bit of fooling around the only solution I have found was to simply add &lt;code&gt;render :layout =&gt; false if request.xhr?&lt;/code&gt; at the end of the edit block. Not DRY at all, but at least I have everything working now. I will update this post if I find a better way.&lt;/p&gt;</body>
    <created-at type="datetime">2010-01-02T06:49:53Z</created-at>
    <id type="integer">9</id>
    <page-type>blog</page-type>
    <published type="datetime">2008-11-17T22:48:00Z</published>
    <slug>rendering-layouts-with-ajax-in-a-restful-controller</slug>
    <title>Rendering layouts with Ajax in a RESTful controller</title>
    <updated-at type="datetime">2010-01-02T06:49:53Z</updated-at>
    <user-id type="integer" nil="true"></user-id>
  </post>
  <post>
    <body>&lt;p&gt;There is a lot of stuff out there for using libnotify with your RSpec and autotest and Ubuntu, but not much for Fedora. Here is how I did it.&lt;/p&gt;

&lt;h3&gt;Install RSpec &amp; Auto Test&lt;/h3&gt;
&lt;p&gt;RSpec instructions to &lt;a href=&quot;http://github.com/dchelimsky/rspec-rails/wikis/home&quot;&gt;install RSpec and RSpec-Rails&lt;/a&gt; as plugins.&lt;/p&gt;
&lt;p&gt;Installing ZenTest is as easy as: (note the caps)&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
# gem install ZenTest
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now you should be able to get autotest running in the terminal. In yours rails project root directory:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
$ rake spec:server:start
$ autotest
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Things should be working in the terminal now.&lt;/p&gt;

&lt;h3&gt;Setting up libnotify&lt;/h3&gt;
&lt;p&gt;We have to install some packages before we go any further:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
# yum install libnotify-devel ruby-gtk2 ruby-gtk2-devel
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Next up we have teh ruby libnofity wrapper,which needs to be installed from source.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
# wget http://rubyforge.org/frs/download.php/27134/ruby-libnotify-0.3.3.tar.bz2
# tar jxf ruby-libnotify-0.3.3.tar.bz2
# cd ruby-libnotify-0.3.3/
# ruby extconf.rb
# make
# make install
&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;Configuration&lt;/h3&gt;
&lt;p&gt;This has been covered quite a bit. So I will just share some links.&lt;/p&gt;
&lt;p&gt;I followed &lt;a href=&quot;http://www.lindenlan.net/2008/03/03/rspec-autotest-and-ruby-libnotify/&quot;&gt;LindenLANs article on the subject&lt;/a&gt; in which I used his ~/.autotest file. And instructions for html reports (including installing launchy).&lt;/p&gt;
&lt;p&gt;I also found some nice pngs for my &lt;a href=&quot;http://blog.aisleten.com/2008/02/21/installing-growlnotify-and-autotest-for-bdd-use-with-rspec-on-leopard/&quot;&gt;pass/pending/fails images from AisleTen&lt;/a&gt; which go in the ~/.autotest_images/ directory.&lt;/p&gt;


</body>
    <created-at type="datetime">2010-01-02T06:45:00Z</created-at>
    <id type="integer">8</id>
    <page-type>blog</page-type>
    <published type="datetime">2008-09-25T22:43:00Z</published>
    <slug>rspec-autotest-and-libnotify-on-fedora</slug>
    <title>RSpec, Autotest and libnotify on Fedora</title>
    <updated-at type="datetime">2010-01-02T06:45:00Z</updated-at>
    <user-id type="integer" nil="true"></user-id>
  </post>
  <post>
    <body>&lt;p&gt;For the last week I have been struggling with a perpetually gray Google map on a client site. I had worked with Google Maps API before and not encountered any thing like this. I could add and remove controls, change points, center the map etc. and not get a single JavaScript error.&lt;/p&gt;

&lt;p&gt;But the kicker was that Firebug showed that all the images were down loading, I could even switch map types and get a whole new set of images.&lt;/p&gt;

&lt;h3&gt;Problem Solved&lt;/h3&gt;

&lt;p&gt;This was a fairly simple problem, but caused hours of headache, so I hope maybe this can help someone else out.&lt;/p&gt;

&lt;p&gt;The problem stemmed from a simple (read: dumb) oversight.&lt;/p&gt;
&lt;p&gt;A css selector was applying float:left; to the Map &amp;lt;div&amp;gt; and all its child &amp;lt;div&amp;gt;s &amp;mdash; resulting in the &lt;abbr title=&quot;Gray Map Of Death&quot;&gt;GMOD&lt;/abbr&gt;.&lt;/p&gt;
&lt;p&gt;Long story short, make sure you are specific with your css selectors!&lt;/p&gt; </body>
    <created-at type="datetime">2010-01-02T06:42:51Z</created-at>
    <id type="integer">7</id>
    <page-type>blog</page-type>
    <published type="datetime">2008-09-19T22:41:00Z</published>
    <slug>google-maps-gray-map-of-death</slug>
    <title>Google Maps Gray Map of Death</title>
    <updated-at type="datetime">2010-01-02T06:46:40Z</updated-at>
    <user-id type="integer" nil="true"></user-id>
  </post>
</posts>
