12.17.07
Posted in Ruby, merb at 11:57 pm by Robert Horvick
I’m getting ready to dive deeper into merb and wanted to install merb_activerecord. Unfortunately when I tried this I hit the following error:
$ gem install merb_activerecord
Updating metadata for 32 gems from http://gems.rubyforge.org
................................
complete
Building native extensions. This could take a while...
ERROR: While executing gem ... (Gem::RemoteFetcher::FetchError)
OpenURI::HTTPError: 404 Not Found reading http://gems.rubyforge.org/gems/activesupport-2.0.2-.gem
So I tried “gem update activesupport” and hit the same error.
I went out to the ActiveSupport RubyForge page found that 2.0.2 was released today. So I went to http://gems.rubyforge.org (which redirected to http://gems.rubyforge.vm.bytemark.co.uk/gems) and the latest version available in 2.0.1. So I assume this is just an issue of needing to wait for data to shuffle around.
But I’m impatient.
So I downloaded the gem file from http://rubyforge.org/frs/download.php/29344/activesupport-2.0.2.gem and installed as:
$ gem install activesupport-2.0.2.gem
Successfully installed activesupport-2.0.2
1 gem installed
Installing ri documentation for activesupport-2.0.2...
Installing RDoc documentation for activesupport-2.0.2...
When that was done I was able to successfully install merb_activerecord as follows:
$ gem install merb_activerecord
Successfully installed merb_activerecord-0.4.3
1 gem installed
Installing ri documentation for merb_activerecord-0.4.3...
Installing RDoc documentation for merb_activerecord-0.4.3...
The lessons here are that just-released gems might not be available via “gem install” even though they are a listed dependency of other gems and that manually downloading and installing gems is trivial.
Permalink
12.14.07
Posted in greasemonkey, javascript at 2:19 pm by Robert Horvick
OpenHulu.com provides a way for the common man to access Hulu.com video content. That’s awesome. However the page sucks. It’s not just the ads either. It’s the layout and the contract between stark white and black. Blegh.
So I decided to pretty it up a little using Greasemonkey (more info at Dive Into Greasemonkey). I’ll let the graphics tell the story:
Before:

And after Greasemonkey:

If this looks better to you install the script from here:
http://www.ghostonthird.com/downloads/openhulu.user.js
This is my first Greasemonkey script. If there is anything obviously stupid - let me know.
For the next version I want to leave the page as-is and instead add a button that will, when pressed, walk the page looking for the active video, make the video nearly almost full screen (leaving the button to toggle the page visible).
This should be more resilient to changes in the page structure.
Permalink
12.13.07
Posted in Ruby, cygwin, merb at 3:39 pm by Robert Horvick
When getting merb working on Windows I provided a patch to the merb folks that resolved a Rakefile compat problem (sudo was being used even when on Windows - where it does not exist).
I’m trying various configurations on Windows and found that in cygwin the platform name does not include “win32″ so the filter no longer worked (and cygwin does not include sudo).
I filed a ticket http://merb.devjavu.com/ticket/361 and attached the patch. It’s very simple:
$ cat cygwin.diffIndex: Rakefile
===================================================================
--- Rakefile (revision 1087)
+++ Rakefile (working copy)
@@ -18,7 +18,7 @@
CLEAN.include ['**/.*.sw?', '*.gem', '.config']
-windows = (PLATFORM =~ /win32/)
+windows = (PLATFORM =~ /win32|cygwin/)
SUDO = windows ? “” : “sudo”
And then it all goes well …
Robert@HORVICKLAPTOP ~/merbsrc
$ rake install
(in /home/Robert/merbsrc)
rake package
(in /home/Robert/merbsrc)
Successfully built RubyGem
Name: merb
Version: 0.4.2
File: merb-0.4.2.gem
gem install pkg/merb-0.4.2 --no-rdoc --no-ri
Successfully installed merb-0.4.2
1 gem installed
Permalink
12.07.07
Posted in Ruby at 1:07 pm by Robert Horvick
As I become more familiar with the Ruby language I have also become more familiar with the global Ruby community (though it will be quite some time before I am familiar to them).
As in all language spaces there are the founders, leaders, thinkers, personalities, corporate players, and random people you’d drink with (if the opportunity presented itself).

What’s interesting about this community, though, is the theme of happiness that everyone keeps talking about.
As in other communities people discuss language features, benefits, failures, frameworks, productivity, metrics, performance, blah blah blah. But this whole notion of happiness, as a language feature, is new to me.
I worked on a commercial compiler for several years early in my career and not once did the word “happiness” come up in design discussions or feature lists. “Tolerable”. “Correctness”. “Performant” (one of my favorite made up words). Absolutely.
But not happiness.
I’m trying to let it soak in slowly. People seem to be happy for basically the same reasons. It boils down to the “feel” of the language. The expressiveness of it. The ease at which things happen. Least surprise. Agile principles. BDD/TDD. RSpec. Lots of good stuff.
And, of course, Rails (and all the MVC, ORM, pluggable goodness it brings to the table).
For me, though, it’s none of those things. Those same things exist in other languages (and will in future languages).
Those things are brick construction, crown modeling and custom paint. Solid. Attractive. Welcoming. Stylish. Fun. But there are other well-made and attractive homes. In the future there will be new well made attractive homes.
Why this one? Why Ruby?
Just like when we picked the neighborhood for our home - it’s the local community. The Raleigh-area Ruby Brigade (Raleigh.rb). Sitting in on the meetings and learning from others. Hearing their stories about past, present and future projects. Listening to their excitement around Ruby and Rails. Learning from them and talking about development topics over laptops and burritos.
Associating with people who are smart, passionate, excited, and who get things done is infectious.
Even just for a few hours a month.
It gets me going. Pushes me to work on my own projects. Revitalizes my spirit. Inspires me to try out new things.

Seeing talented developers with a flare for design pushes me to improve my design skills. I’ve begun reading about graphic design, typography, print layouts, usability and photo processing. I’ve started to draw again. I’m sleeping less (in a good way), thinking more, and generally more excited about my day-to-day work (C#, not Ruby). I’m reconnecting with that person I used to be before I got trapped in the clutches of a monolithic corporate machine. He is much cooler than I am. At least he had better taste in socks.
None of this is really about Ruby as a language, though. It could just as well be Python or a Linux fetish. I’m sure there are some great local groups for those technologies.
But I’m not in those groups. I’m in Raleigh.rb. Maybe I’ll check them out some other time. Maybe not. I’m still having fun here.
So go now. Seek out a local Ruby Brigade in your community. If you can’t find one then start your own.
Sit in the back. Don’t say a word. Or sit up front and chat the place up. Doesn’t matter. Just find one and go. If you’re in the Raleigh area come by to the local meetup. I’ve found it to be a friendly, open group who enjoy seeing new faces.
Make it a New Year’s resolution.
You’ll be glad you did.
I promise.
Permalink
11.29.07
Posted in Ruby, rails at 5:00 am by Robert Horvick
To give users a better view into some data I want to render local points of interest with current deals onto a Google map. In the marker popup I’d like the user to be able to drill down further into the details. To do this I want a hyperlink to the deal details.
The link_to I want is:
link_to "Details", { :controller => "deal", :action => "details", :id => deal.id }

The problem is that the rendered <a> should go into a blob of javascript such as:
GEvent.addListener( marker,"click", function() {
var myHtml = "<b><%= h deal.Restaurant.name %></b><br/><%= h deal.description %></br><%= link_to "Details", { :controller => "deal", :action => "details", :id => deal.id } %>";
map.openInfoWindowHtml(marker.getLatLng(), myHtml);
}
);
That fails because the string literal has embedded double quotes.
Since ‘h’ (alias for html_escape) exists I figured there had to be a javascript version as well - and action view did not disappoint.
The updated code is:
GEvent.addListener( marker,"click", function() {
var myHtml = "<b><%= escape_javascript h(deal.Restaurant.name) %></b><br/><%= escape_javascript h(deal.description) %></br><%= escape_javascript link_to("Details", { :controller => "deal", :action => "details", :id => deal.id }) %>";
map.openInfoWindowHtml(marker.getLatLng(), myHtml);
}
);
The javascript now renders correctly and the link to the details page functions as expected.
I’m still shooting in the dark - but I think I’m facing the target.
Permalink
11.28.07
Posted in Ruby, rails, rspec, testing at 6:00 am by Robert Horvick
Since bringing a copy of my current project down from heroku to test some features I decided to give RSpec a try at the same time.
My gut feeling was to run “gem install rspec”. So, for the record, that is NOT the way to properly install rspec on a rails site.
To use rspec on a rails site you need to install it as a plugin.
The documentation page on installing RSpec indicates that I should do this be running the following commands from my ruby shell:
ruby script/plugin install svn://rubyforge.org/var/svn/rspec/tags/CURRENT/rspecruby script/plugin install svn://rubyforge.org/var/svn/rspec/tags/CURRENT/rspec_on_rails
When I did this nothing happened. No output whatsoever.
I tried running the next command on the install guide (output provided):
>ruby script/generate rspec
Couldn't find 'rspec' generator
I figured the problem was not having svn installed (let me take a moment here to say that the plugin script could do a better job of indicating this - silent failure smells a lot like success).
I installed downloaded the win32 client binaries from the subversion site http://subversion.tigris.org/downloads/1.4.5-win32/apache-2.2/svn-win32-1.4.5.zip and extracted them to c:\svn (so c:\svn\bin now contains svn.exe).
In my ruby command shell I added c:\svn\bin to the path (set PATH=%PATH%;c:\svn\bin) and now re-running the plugin installation succeeded (thousands of lines of status scroll by).
Next I ran the following (with output):
C:\InstantRails\rails_apps\kidseatfree>ruby script\generate rspec
exists spec
create spec/spec_helper.rb
create spec/spec.opts
create previous_failures.txt
create script/spec_server
create script/spec
Finally I ran “rake spec” - which showed I had a missing gem dependency:
C:\InstantRails\rails_apps\kidseatfree>rake spec
(in C:/InstantRails/rails_apps/kidseatfree)
C:/InstantRails/rails_apps/kidseatfree/vendor/plugins/rspec/lib/spec/runner/formatter/base_text_formatter.rb:37:in `colour=': You must gem install win32console to use colour on Windows (RuntimeError)
So I ran “gem install win32console” and now rake spec gave the following (I already had an rspec test written so there was something to do):
Errno::ENOENT in 'Deal with fixtures loaded should have one record'
No such file or directory - C:/InstantRails/rails_apps/kidseatfree/config/../spec/fixtures/deal
So I copied my fixtures from test\fixtures to spec\fixtures and re-ran:
C:\InstantRails\rails_apps\kidseatfree>rake spec
(in C:/InstantRails/rails_apps/kidseatfree)
..Finished in 0.166 seconds
2 examples, 0 failures
Permalink
11.26.07
Posted in Programming, Ruby, ajax, heroku, rails at 4:55 pm by Robert Horvick
Update: As I expected the guys are heroku turned around a fix very quickly. I tested autocompletion tonight and it worked perfect. heroku + script.aculo.us = working like a champ :)
They say that constructive criticism (e.g. complaints) should occur in a sandwich of positive thoughts. Generally I think that’s a bunch of PC granola-farming nonsense. People need to hear what people need to hear. If I suck - tell me. If I’m lucky you’ll tell me why. If I’m really lucky you may offer advice on how to improve.
But knowing that something sucks is the baseline.
But I’m going to break my rule and go with the PC warm-fuzzy approach.
Positive: Heroku kicks ass
Rails site online fast, syntax highlighting editor, backup/restore, nginx, postgres … love it. I’ve been able to make a lot of progress in this environment (and being able to work on the site from multiple computers is very nice).
Negative: Heroku injects some code into every response
This breaks ajax behaviors by altering partials (and includes prototype.js which breaks script.aculo.us) … in short ajaxy rails is broken.
When I make an ajax request I expect to get back something like:
<ul class="restaurants">
<li class="restaurant"> <div class="name">rest name</div>
</li>
<li class="restaurant">
<div class="name">O'Charley's</div>
</li>
<li class="restaurant">
<div class="name">Sunday Deal</div>
</li>
<li class="restaurant">
<div class="name">Monday Deal</div>
</li>
<li class="restaurant">
<div class="name">Sunday Cheap</div>
</li>
</ul>
But what I actually get back is:
<!-- heroku toolbar -->
<script src="http://heroku.com/javascripts/prototype.js” type=”text/javascript”></script>
<script src=”http://heroku.com/javascripts/effects.js” type=”text/javascript”></script>
<script src=”http://heroku.com/toolbar/heroku_toolbar.js” type=”text/javascript”></script>
<link href=”http://heroku.com/toolbar/heroku_toolbar.css” media=”screen” rel=”Stylesheet” type=”text/css” />
<script type=”text/javascript”>HerokuToolbar.html = ‘<div id=”heroku_toolbar”><a href=”http://heroku.com” id=”heroku_logo”></a><a href=”http://edit.kidseatfree.heroku.com/?uri=%2Fdeal%2Fauto_complete_for_restaurant_name” id=”heroku_back_button”></a><a href=”javascript:HerokuToolbar.toggle()” mce_href=”javascript:HerokuToolbar.toggle()” id=”heroku_inspect_button”></a><img id=”heroku_spinner” src=”http://heroku.com/toolbar/images/spinner.gif” style=”display: none”><span id=”heroku_login_info”><a href=”http://heroku.com/myapps”>robert.horvick@gmail.com</a> | <a href=”http://heroku.com/logout”>logout</a></span></div>’</script>
<span class=”heroku_marker heroku_start” style=”display: none”>/mnt/home/userapps/347/app/views/deal/_restaurants.rhtml</span>
<ul class=”restaurants”>
<li class=”restaurant”> <div class=”name”>rest name</div>
</li>
<li class=”restaurant”>
<div class=”name”>O’Charley’s</div>
</li>
<li class=”restaurant”>
<div class=”name”>Sunday Deal</div>
</li>
<li class=”restaurant”>
<div class=”name”>Monday Deal</div>
</li>
<li class=”restaurant”>
<div class=”name”>Sunday Cheap</div>
</li>
</ul>
<span class=”heroku_marker heroku_finish” style=”display: none”></span>
Ah crap. Now my autocomplete doesn’t render … oh but it gets worse.
Reincluding prototype.js causes the scriptaculous extending of Ajax.Autocompleter to be lost and now autocomplete events don’t fire (in fact FireBug shows an error because Ajax.Autocompleter is not a constructor).
Bug reported.
Positive: The folks at heroku kick ass
I have reported quite a few issues - some bugs, some feature ideas, some random rants about usability or business models. But in every case these guys have turned around fixes or offered workarounds in a matter of hours.
The issue I just described - I’m confident that they will be able to work past it quickly or provide some sort of workaround for the specific case of partials.
So there you go.
A feedback sandwich.
Now I’m hungry.
Permalink
11.25.07
Posted in MySQL, Programming, Ruby, rails at 6:10 pm by Robert Horvick
I want to create a simple site that allows users to add event, restaurant and location details through an ajax-ish interface. Ultimately I have a design in mind but to get there I need to be able to submit details of multiple models through a single form (there are about 10 fields over 4 models that will need to be defined).
I wanted to use the action view “form_for”, a single submit and have the submission automatically map the fields to their proper object so that my controller method could look like this (sans error handling):
def create
if request.post?
@deal = Deal.new(params[:deal])
@deal.Restaurant = Restaurant.new(params[:restaurant])
@deal.Location = Location.new(params[:location])
@deal.save
end
end
Long story short - what you need to do is use the “fields_for” call within the form to get the model information. The form in the view looks like:
<% form_for :deal, :url => { :action => :create } do |form| %>
<% fields_for :restaurant do |r| %>
Restaurant: <%= r.text_field :name %><br/>
<% end %>
<% fields_for :location do |l| %>
Address 1: <%= l.text_field :address1 %><br/>
Address 2: <%= l.text_field :address2 %><br/>
City: <%= l.text_field :city %><br/>
State: <%= l.text_field :state %><br/>
Zip: <%= l.text_field :zip %><br/>
<% end %>
Details: <%= form.text_area :description, :rows => 3 %>
<%= submit_tag %>
<% end %>
In this example three models are used - Deal, Restaurant and Location.
The form is based on Deal (since I want the submit to go to Deal::create and I defined two fields_for blocks - one for Restaurant and Location.
The params.inspect output of the form data is:
Parameters: {”restaurant”=>{”name”=>”rest name”}, “deal”=>{”description”=>”Kids can eat whatever they want in under 3 minutes.”}, “commit”=>”Save changes”, “location”=>{”city”=>”some place”, “address1″=>”address one”, “zip”=>”12345″, “address2″=>”", “state”=>”NC”}}
Notice that restaurant, deal and location are all their own hash which can be passed to the new method on the respective models.
Worked like a champ.
Details on the schema is:
create_table :locations do |t|
t.column :address1, :string, :limit => 60
t.column :address2, :string, :limit => 60
t.column :city, :string, :limit => 40
t.column :state, :string, :limit => 2
t.column :zip, :string, :limit => 10
t.column :phone, :string, :limit => 16
t.column :lng, :string, :limit => 30
t.column :lat, :string, :limit => 30
t.column :restaurant_id, :int
end
create_table :restaurants do |t|
t.column :name, :string, :limit => 60
end
create_table :deals do |t|
t.column :restaurant_id, :int
t.column :location_id, :int
t.column :description, :text
end
And the models relationships:
class Deal < ActiveRecord::Base
belongs_to :Restaurant
belongs_to :Location
...
end
class Location < ActiveRecord::Base
belongs_to :Restaurant
end
class Restaurant < ActiveRecord::Base
has_many :Location
has_many :Deal
...
end
Permalink
11.23.07
Posted in Uncategorized at 1:57 pm by Robert Horvick
I was checking RubyCorner’s updated feed and came across a post on rssHugger.com. In a nutshell the service (manually) reviews and categorizes submitted blogs into high-level topics (such as Technology, Finance and Humor).
It’s a similar idea to other web directories except that in addition to a site link it also provides a feedlink (which makes it similar to sites like bloglines, technorati, etc)
When I first read about the site what I expected to find was the ability to drill down to a category such as “Technology -> Programming -> Ruby” and subscribe to an aggregated feed of all the blogs in that category (similar to RubyCorner.com) but instead it is just a list of blogs with direct links to the site and feed (with less granular categorization - “Technology” exists but not “Programming” or “Ruby”).
Likewise I also expected to be able to subscribe to aggregated lists based on tags - but that does not seem possible either.
I also thought I might be able to create my own aggregated feed that I could share with others.
Finally I expected to be able to search blogs in a free-form way but the search link takes me to the directory list - not an actual search engine. That may be OK when there are only 23 registered blogs (with a goal of 250,000 the first year) - but as the number grows the ability to find interesting content is critical.
I don’t know what features are in the pipeline but right now it’s just a loosely categorized list of sites and feeds.
So to summarize - what it needs:
- More granular categories.
- Aggregated feeds by category
- Aggregated feeds by tags
- The ability to create my own feed lists (and give me some widgets to share on my blog)
- Meaningful search (for sites and posts)
- More sites.
Do a few of 1-5 and 6 will happen on it’s own.
Permalink
« Previous entries · Next entries »