Navigation

ADS specializes in using Ruby on Rails to build advanced, scalable, database-backed web sites for organizations of all sizes. Find out more at our website.

Atlantic Dominion Solutions

The first half of 2008 has seen a great number of happenings in the Ruby and Rails worlds. Here are the top ten for the first half of 2008.

  • June 23, 2008 - Rails scales - LinkedIn serves 1 billion pages using Rails
  • June 1, 2008 - Rails 2.1 is released
  • May 31, 2008 - Ruby 1.8.7 is released
  • May 30, 2008 - Joel Spolsky keynotes RailsConf 2008
  • May 30, 2008 - FiveRuns released TuneUp to help with Rails performance optimization
  • May 27, 2008 - JRuby 1.1.2 is released, and runs Rails 2.1 like a champ
  • April 13, 2008 - Phusion Passenger (mod_rails) is released
  • April 11, 2008 - Rails core moves to Github, prompting many to move with them
  • April 2, 2008 - Morph Labs makes Rails deployments to EC2 a cinch
  • January 1, 2008 - Thin comes on the scene as an alternative to Mongrel

See something I missed? Drop us a comment below.

Share this post

I’m proud to be talking about Leveraging the Cloud with Ruby at the Ruby Hoedown this coming August. Ruby Hoedown is a regional Ruby conference held this year in Huntsville, Alabama. There is a great lineup of speakers and it should be a great time.

I’ll be discussing cloud computing and showing rich code examples of how Ruby developers can use services such as Amazon Web Services to build highly scalable applications. Do you want to see something specific? If you’re attending Ruby Hoedown and would like to see something in particular leave a comment here. Register for the Ruby Hoedown today and I’ll see you in August!

Share this post

I was getting a little fed up touching every single directory that was empty after I created a new Rails app and than pushing it to a git repo and having it not include the empty directories. So, I created a short quick script to help me out. I didn’t test it more than a couple times, but it seems to do the job. Anyway, here it is:

def touch_gitignore(path = '.')
  Dir[File.join(File.expand_path(path), '**')].each do |file|
    if File.directory?(file)
      touch_gitignore(file)
      if Dir[File.join(file, '*')].empty?
        `touch #{File.join(file, '.gitignore')}`
        puts 'touched: ' + file
      end
    end
  end  
end
 
ARGV.first ? touch_gitignore(ARGV.first) : touch_gitignore

Yes, I’m sure it can be improved. As I said, it was quick and dirty, out of frustration even.

As an example how to run it, if I named the file I pasted the code from above into ‘gitignore.rb’ then it would be something like this:

chris$ rails test
chris$ ruby gitignore.rb test

If you found this useful, how about a recommendation on working with rails?

Share this post

You’ve given us feedback and we have listened.

My goal with whatsupinruby.com (and the other what’s up sites we will be releasing) is to get rid of my RSS reader. To do this, I need the site to do two things:

  • Tell me what people are talking about in a given context
  • Take me to those conversations so I can learn more

Whatsupinruby.com does the first, but frankly falls down in the second. The issue is our approach. Rather than our results being a list of the latest posts on the topic (in this case Ruby and associated technologies) it spiders all things Ruby and returns Google-like results based on links, keyword frequency, etc. While that is what we built and what I originally asked for, that is not what I want. What I want is a list of sites that are talking about the conversation item I am interested in (i.e. ruby, rails, memcache, etc.).

Another point of confusion (again caused by me) is the search box and its prominence on the site. The real reason for the site isn’t search (which you can use Google for) but rather to be kept up to date on the latest conversation. The prominence of the search box takes away from that in a big way. We are changing that.

We are currently updating the site as follows:

  • Updating the site design to give prominence to the conversation items rather than the search box
  • When you click on a conversation item it will auto-search rather than putting the search term in the search box
  • Results returned by a search will be a list of the latest blog posts that are discussing that item
  • Even more to come in 1.0

What do you all think? Will that make what we are doing more or less relevant to you all? Will the updates we are putting in place help people to understand our goal? We’d love and welcome all of your feedback.

Our goal is to put out the improved whatsupinruby.com by early next week.

Share this post

Have you ever wanted to create a form with the nice ActiveRecord Validations, but not use a database or ActiveRecord model? Like if you wanted to just have the result of the form emailed. An example might be a contact form or a special inquiry form that requires a name, an email, and perhaps a phone number.

Well, you can, and it”s quite easy too. Especially with the help of a little gem called Validatable.

To install:

sudo gem install validatable

There are at least 2 ways to include this in your Rails project, I’m going to cheat and use the shortcut method of including it in the environment.rb file to save on time and typing (and your patience):

Add to your environment.rb file:

require "validatable"

Next, lets create a new class file called contact.rb. You can put this in lib, models, or some other place, it”s up to you. I put it in my models directory for this example.

The contents of contact.rb will look like the following:

class Contact
  include Validatable
 
  attr_accessor :name, :email, :phone, :message
 
  validates_presence_of :name, :message => "Name is required."
  validates_format_of :email, :with => /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i,
    :message => "Email is not valid."
  validates_format_of :phone, :with => /^[0-9]{3,3}-[0-9]{3,3}-[0-9]{4,4}$/,
    :message => "Phone number is not valid (xxx-xxx-xxxx)."
 
  def phone=(phone)
    @phone = phone.gsub(/[^0-9]/, "").gsub(/^([0-9]{0,3})([0-9]{0,3})([0-9]{0,})$/) do |match|
      tmp = ""
      tmp += $1 if $1.size > 0
      tmp += "-" + $2 if $2.size > 0
      tmp += "-" + $3 if $3.size > 0
      tmp
    end
  end  
 
  def deliver
    if valid?
      Notification.deliver_contact(self)
    else
      false
    end
  end
end

Oh my, doesn”t that look familiar? It looks just like an ActiveRecord model, except, gasp! It doesn”t inherit from ActiveRecord::Base. It”s just a plain Ruby class. Spiffy!

I”m assuming everything else looks familiar to you, yes? Swell, moving on then.

You will also notice I have a Notification mailer in there.

Note: I”m assuming you also know how to set up a mailer and the respective views. If you do not, comment below and I will add those pieces to this post if you desire.

Try it out, open up your console and play around.

>> c = Contact.new
=> #<Contact:0x218e974>
>> c.name = "Chris"
=> "Chris"
>> c.valid?
=> false
>> c.errors.full_messages
=> ["Email Email is not valid.", "Phone Phone number is not valid (xxx-xxx-xxxx)."]
>> c.email = "chris@techcfl.com"
=> "chris@techcfl.com"
>> c.phone = "1234567890"
=> "1234567890"
>> c.valid?
=> true
>> c.name
=> "Chris"
>> c.email
=> "chris@techcfl.com"
>> c.phone
=> "123-456-7890"
>> c.message = "Stillwater? Wtf is that?"
=> "Stillwater? Wtf is that?"

Cool! Now let”s put this into Rails context and see how to use it for handling validations in our controller and view.

In the controller where you want to handle your contact form, you might have something like the following:

def contact
  @contact = Contact.new
  if request.post?
    @contact.name = params[:name]
    @contact.email = params[:email]
    @contact.phone = params[:phone]
    @contact.ticker = params[:ticker]
    if @contact.valid?
      @contact.deliver
      flash[:notice] = "Thank you for you interest."
      redirect_to root_url
    end
  end
end

Here is an example view with custom error handling:

<% form_tag contact_path do %>
  <table>
    <tr>
      <td>
        <label for="name">Name:</label>
      </td>
      <td>
        <%= text_field_tag "name", @contact.name %>
        <%= error_messages_for_attribute(@contact, :name) %>
      </td>
    </tr>
    <tr>
      <td>
        <label for="email">Email:</label>
      </td>
      <td>
        <%= text_field_tag "email", @contact.email %>
        <%= error_messages_for_attribute(@contact, :email) %>
      </td>
    </tr>
    <tr>
      <td>
        <label for="phone">Phone:</label>
      </td>
      <td>
        <%= text_field_tag "phone", @contact.phone %>
        <%= error_messages_for_attribute(@contact, :phone) %>
      </td>
    </tr>
    <tr>
      <td>
        <label for="message">Message:</label>
      </td>
      <td>
        <%= text_area_tag "message", @contact.message %>
        <%= error_messages_for_attribute(@contact, :message) %>
      </td>
    </tr>
    <tr>
      <td colspan="2">
        <%= submit_tag "Submit" %>
      </td>
    </tr>
  </table>
<% end %>

You will notice a custom error_messages_for_attribute helper method I created, here is the code I used for that:

def error_messages_for_attribute(object, attribute)
  if object.errors.on(attribute)
    html = '<small class="errors"><ul>'
    object.errors.on(attribute).each do |message|
      html += "<li>" + message + "</li>"
    end
    html += "</ul></small>"
  end
end

I hope you found this useful.

Share this post

JRuby 1.1 RC2 Released

By: Robert Dempsey | Tags:

Thomas Enebo announced the release of JRuby 1.1 RC2 this past Saturday. The focus of the release is improved speed and refinement. He also says that RC2 uses less memory, and can compile in either Ahead of Time (AIT) or Just In Time JIT) mode. Charles Nutter then followed up with a post of his own letting us know what is next on the agenda for the JRuby team.

They are asking for you to download RC2 and provide feedback.

If you’ve used JRuby, let us know about your experience.

Connect with me on LinkedIn, Twitter, or recommend me on Working With Rails.

Share this post

Ruby 1.9.0 Released

By: Robert Dempsey | Tags:

Yukihiro “Matz” Matsumoto and the Ruby core team announced on the ruby-talk mailing list the release of Ruby 1.9. According to Cheah Chu Yeow, mongrel is almost fully 1.9 compatible as is Rails. Before enjoying the big speed boost and new features of 1.9, grab a copy and test it local. Enjoy!

ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.0-0.tar.bz2 - 407cc7d0032e19eb12216c0ebc7f17b3

ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.0-0.tar.gz - b20cce98b284f7f75939c09d5c8e846d

ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.0-0.zip - 78b2a5f9a81c5f6775002c4fb24d2d75

UpdateMany others, including Dave Thomas, have reported that this is a development release, so definitely keep it local for now.

Share this post