about img
blogger img

UnderPaidLoveMonkis posts img

buchos posts img

scotts posts image

Corys posts image

Rails's Archive

Rails in browser IDE / instant deployment

Scott Rippee @ 2:13 am Thursday, February 14th, 2008

This caught my eye on Riding Rails Blog the other day. This site has a built in rails IDE. This looks nice in the demos, but it would be interesting to actually give it a spin to see if it’s usable. The coolest thing is the instant deployment of the rails app to Amazon’s EC2! This seems like it would be very attractive to someone just getting started with rails since you would get to put full focus into the development and skip the other pains in the ass (deployment, capistrano, web servers, mongrel instances….).

Rails 2.0 is out!

UnderpaidLoveMonki @ 10:00 pm Thursday, December 6th, 2007

Lo and behold after I performed a “gem update” tonight, I started seeing rails 2.0 being installed! WOOHOO! Let the games begin! It’s a good christmas afterall! :)

UPDATE, Part 2: Activeresource finally showed up in the mirrors and it is now installed. Rails is running perfectly! Awesome!

UPDATE: Oop, I spoke too soon:

ERROR: While executing gem … (Gem::GemNotFoundException)
Could not find activeresource (= 2.0.0) in any repository


Pick Your RoR HTML Parsing Poison

Scott Rippee @ 4:07 pm Thursday, July 5th, 2007

Ruby HTML parsing has been keeping me quite entertained frustrated lately, so I thought I'd share some thoughts. There are a couple of instance in your rails app when you'll want to parse HTML

  1. Automated functional/controller testing
  2. Screen scraping

Functional Testing

The standard method of verifying aspects of resulting HTML in your functional test is HTML::Selector. It's simple, powerful, and baked in. Agile Rails 2nd does a great job of explaining how it's used in functional tests.

  1. def test_add_no_name
  2.   post :add, :color => { :name => '', :hex => '#123456' }
  3.   assert_template 'add'
  4.   assert_select "div[id=errorExplanation]" do
  5.     assert_select "ul" do
  6.       assert_select "li", 'Name is not present'
  7.     end
  8.   end
  9. end



Several options are available, but oh so popular is why's Hpricot. It's fast and enjoyable (although I experienced no joy while learning how to use it =) It also happens to be used in some of the other scraping/navigating libraries (WWW::Mechanize [rdoc] and scRUBYt!).


Some Thoughts...

So if your just concerned with testing use HTML::Selector and the built in asserts. If you have to do very basic screen scraping I would also suggest going with HTML::Selector (as long as speed is not an issue and the scraping is basic) with open-uri or curb for fetching the pages.

For more serious screen scraping bust out Hpricot and if you need to navigate pages via automation use WWW::Mechanize (Mechanize also uses Hpricot so all of that Hpricot knowledge you've absorbed is directly applicable. Mechanize is Hpricot with the ability to click). Don't worry about scRUBYt!. It's more of a pain to figure out than it's worth (but maybe I'm wrong about it. Any good examples/write-ups?).

Hpricot with CSS selector

  1. divs = (doc/"div[@style*='font-weight:'][text()*='$'").inner_html
  2. divs.each do |div|
  3.   if div =~ /\$[0-9]?[0-9]\.[0-9][0-9]/
  4.     self.price = div.to_s.sub('$', '')
  5.   end
  6. end

Hpricot search with XPath

  1. require 'hpricot'
  2. require 'open-uri'
  3. doc = Hpricot(URI.parse("http://google.com/").read)
  5. doc.search("/html/body//p")
  6. doc.search("//p")
  7. doc.search("//p/a")
  8. doc.search("//a[@src]")
  9. doc.search("//a[@src='google.com']")

Using Mechanize to do a search on google

  1. require 'rubygems'
  2. require 'mechanize'
  4. agent = WWW::Mechanize.new
  5. agent.user_agent_alias = 'Mac Safari'
  6. page = agent.get("http://www.google.com/")
  7. search_form = page.forms.with.name("f").first
  8. search_form.q = "Hello"
  9. search_results = agent.submit(search_form)
  10. puts search_results.body

Note that Hpricot lets you use a CSS method of selecting and an XPATH method. Use XPATH if you already have experience otherwise the CSS method is more intuitive.

If you go with XPATH grab the XPather firefox plugin and use it with the DOM Inspector. Also, it works with the firebug firefox plugin. I'm still in awe that it worked when I tried. :) To do this, use firebug to "inspect", choose an element, right click on the page and select "Show in XPather". XPather will open with the selected element locked and loaded.

Finally, if your a Hpricot wiz forget about HTML::Selector and put Hpricot to work for view validation in your functional tests. See this great write up, Testing your Rails views with Hpricot, which demonstrates this elegant solution.

  1. assert_equal "My Funky Website", tag('title')
  2. assert_equal 20, tags('div.boxout').size
  3. assert_equal 'visible', element('div#site_container').attributes['class']


Rails Caching

UnderpaidLoveMonki @ 2:43 pm Thursday, July 5th, 2007

If you have to deal with Rails caching, you might want to read this for some cool tricks & tips.

By doing this you get the bandwidth savings of HTTP caching, the performance boost of action caching, but without the difficult expiry code. You can avoid all the NFS related headaches of page caching, but still get most of the performance boost.

Quality Fast Cheap VPS Hosting

Scott Rippee @ 10:19 pm Sunday, June 10th, 2007

I've been using for ruby on rails hosting/development and subversion hosting for over 6 months now (before they had a waiting list).

Quad processor machines, RAID1 drives, Tier-1 bandwidth and root access. Managed with a customized Xen VPS backend to ensure that your resources are protected and guaranteed.

What makes them so popular they have this wait that they continue to battle with?

Obviously the speed, but also:

  • Scalability - bring up as many new slices as needed instantly (well a few minutes for the drive to be imaged) or add more storage space to an existing slice
  • Distro choice (gentoo, ubuntu, debian, centos, fedora)
  • Full root access
  • Live backups on a daily and weekly schedule of the running instance of your slice
  • Take snapshots at any time of a running instance (very nice for after you get a slice configured)
  • Uhhh speed again (they do not and will not overbook their resources)
  • Price (you can't beat 20 bucks a month for VPS)

If your not up to par with Linux administration I wouldn't recommend this as you'll need to get your box up and running from scratch.

They've also just added DNS management to their custom rails admin section, so I can cancel my EveryDNS account. Which provided excellent DNS service by the way and for free!

Ruby on Rails commercial!

UnderpaidLoveMonki @ 9:48 pm Friday, June 8th, 2007

Quite hilarious... :)

You go, Ruby on Rails!

RoR Reserved Words

Scott Rippee @ 9:13 pm Wednesday, May 30th, 2007

The errors that occur when you use a reserved word tend to be very confusing. Things that you think are happening in your code, are actually happening somewhere in the framework. Sometimes you can look at the stack trace and see that its not going through your class, but through some framework class. If you have an error that makes no sense at all, I would check to make sure you don’t have a name that conflicts with the above list.

It would be nice to go back in time and tell myself to read this a few days pre now.

Rails app in a single executalbe??

Scott Rippee @ 7:45 pm Monday, May 28th, 2007

moab Petroglyph src wikipedia
This is quite impressive. It documents how to wrap up a whole rails app into one executalbe.

Driving this magic is RubyScript2Exe, which packages ruby scripts into executables for linux, mac, or windows. I'm sure I'll have a use for this one.


ruby-debug - =]

Scott Rippee @ 5:49 pm Monday, May 28th, 2007

cc by Designerdruby-debug = cool + very useful. Many have said it before and I have blissfully ignored until in a sticky situation that helped me realize I need to be able to poke and prod a little more than spitting out to the log in rails. After all poke and prod is my favorite way to learn.

It's has a simple feel, yet is powerful letting you drop into a debug shell where you can set breakpoint, move through the stack, step around, and examine variables. I was pretty hesitant about learning ruby-debug as I had thoughts of gdb in my head. I have a dislike/fright of gdb and continue to gimp around with it despite a lot of use. ruby-degub, however, is no foe.

No need to cover installing or usage here, as these fine people have created useful docs and even a screencast...

Install and use with RAILS

Common usage


Data Noise - Developers blog

Markaby Markaby Markaby

Scott Rippee @ 10:20 pm Sunday, May 6th, 2007

Markaby's for rails by why (who has recently took up creating a potentially very fun, pratical way for the youth to get involved with programming, Hackety Hack. Cool)

Markaby rids the dirty syntax of intertwined html and ruby in your view
<%= %>.destroy

Markaby supports the rails notion of top to bottom ruby code in web development

Behavior Driver Development Example

Scott Rippee @ 1:08 pm Sunday, March 11th, 2007

Over at Giant Robots... Tammer Saleh writes about using rSpec with Spec::Rails. This post shows how natural language is used to write the spec in the code and how running it produces meaningful information along with the verification of the statements.

Running your own OpenID server

UnderpaidLoveMonki @ 6:43 am Friday, March 9th, 2007

From OpenID Enabled, you can download OpenID server in an implementation of your favorite language. It's open source. Port it to your language of choice if you don't see it on the list.

Hmmm....I don't see an implementation in Erlang. Imagine the flexibilty of OpenID server's decentralization implemented in Erlang, a derivative of Prolog, that is highly scalable, fault tolerant.

By the way, Programming Erlang will be out soon. There's also a Rails plugin, open_id_authentication. I got too many ideas, too little time. *SIGH* Good times anyways! :)

Intarweb while drunk: Rails, Mongrel, Apache, Capistrano and You

Scott Rippee @ 8:53 pm Saturday, January 6th, 2007

It’s true, Apache + FastCGI is a horrible, horrible solution, unless your problem is “how can I waste my time on a dodgy server config?” in which case you shouldn’t be using the Intarweb while drunk.

I'm currently putting together a Rails, Mongrel, Apache configuration (maybe capistrano....). I was glad to find this article while looking how to use apache, with mod_proxy_balancer, and Mongrel instances.

HowTo: Install FastCGI and Ruby on Rails on Redhat Enterprise

UnderpaidLoveMonki @ 9:26 pm Saturday, January 14th, 2006

Here's a quick guide (written on scratch paper, but now published in this blog, so packages may be newer now) how I got Ruby on Rails and FastCGI for Apache2 running in Redhat Enterprise Linux ES release 4 (Nahant Update 2) on a production Dell PowerEdge server.

Note: This works on my box. So YMMV and use it at your own risk. I'm not responsible nor will troubleshoot your problems if they arise.

Because of its packages are a bit dated and needed newer versions to run my rails applications, this is what I did to get the newer packages installed on this box.


HowTo: Install Ruby, RubyonRails, and RubyGems on Ubuntu 5.10 (Breezy)

UnderpaidLoveMonki @ 10:07 pm Friday, January 13th, 2006

Here's a quick guide if you're running Ubuntu (should also work with Debian).

1. Install ruby and rubyonrails

sudo apt-get install ruby rails

2. Install RubyGems (you can install ruby apps that are not found in the Ubuntu respository)

a) Download rubygems-0.8.11.tgz (at the time of this writing) from http://docs.rubygems.org

b) Unpack it, navigate into the directory, and type the following command:

i) $ cd rubygems-0.8.11

ii) $ sudo ruby setup.rb

iii) $ sudo gem install rubygems-update

4. Install Ruport (a report generator) via RubyGems

a) $ sudo gem install ruport

b) $ ruport -v

5. Test ruby-dbi database connector (should be installed with rails)

Save the following Ruby script as test.rb:

# simple.rb - simple MySQL script using Ruby DBI module
require "dbi"
# connect to the MySQL server
dbh = DBI.connect("dbi:Mysql:mydatabasename:localhost", "root", "laughwithme")
# get server version string and display it
row = dbh.select_one("SELECT VERSION()")
puts "Server version: " + row[0]
rescue DBI::DatabaseError => e
puts "An error occurred"
puts "Error code: #{e.err}"
puts "Error message: #{e.errstr}"
# disconnect from server
dbh.disconnect if dbh

6. Execute script: $ ruby test.rb

If the dbi connector is present, the script output should output the MySQL version.

7. Execute Ruport

a) $ ruport generate test (it'll create a directory called test and generate templates)

b) $ cd test

c) $ edit database config file by:
nano config/ruport.yaml
:driver: 'DBI:mysql'
:database: 'testdb:localhost'
:db_user: 'testuser'
:db_password: 'testuser'

8. generate report by executing the following command:

ruport templates/test.rb