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

There is no spoon Is there some magic in a version number that I don’t know about? There must be, since so many applications use version numbers. I was thinking about this as I was adding tickets to the project from which What’s up in Ruby sprang, and mindlessly creating versions and putting tickets under each.

What constitutes a version? Is it a certain number of bug fixes or features? Perhaps a combination of both?

It struck me that in the web development world we don’t put version numbers on our apps, at least not externally. Last week we offered this set of features, and this week we have these new features. Great! But mommy always said it is good to have goals, so what are we to do?

First, stop labeling anything “beta” or “alpha” or “version 1.” There’s either something out there, or there isn’t. It might be available to a select few, but it’s out there.

Second, implement scrum. Put all of your tickets into a backlog and prioritize them. Plan what you will do for a sprint (10 working business days for us), do it, and then deploy it. At the end of that sprint you should have potentially shippable product. If you need more time extend the sprint. Be flexible with what a sprint means to you, as long as it isn’t longer than a month.

Don’t make your users wait for new features. If they work, put them out there. Get feedback quickly and respond accordingly. Software is continuously evolving. Let that evolution happen incrementally rather that in giant leaps. Involve your users in the process and you will reap the reward: happy users.

Share this post

TechCrunch posted a rumor yesterday that Twitter was going to ditch Rails for PHP or something else. This is not true. Evan Williams tweeted that this was indeed false:

“FWIW: Twitter currently has no plans to abandon RoR. Lots of our code is not in RoR, already, though. Maybe that’s why people are confused.”

I loved David’s response to the scaling argument in a recent eWeek article:

“This is known as the ‘Last Stance’ defense. When you have nothing of left of substance to argue with, you draw the ‘But does it scale?’ card. This is on page one of the Fear, Uncertainty and Doubt playbook.”

Wikipedia defines scalability as, “ability to either handle growing amounts of work in a graceful manner, or to be readily enlarged.” We can do that with Ruby and Rails, just as you can do that with many other programming languages and frameworks. People seem to forget that scalability is not simply a matter of code but the architecture of the application and the infrastructure the app is sitting on. If you design an application without growth in mind you’ll have issues, hands down. If you host your application on shared hosting and don’t give it the resources it needs you’re going to have issues.

“Can Rails scale?” is the wrong question to be asking. The right question is “how do we scale properly?”

Share this post

While normally an OSX and TextMate user, of late I’ve had need to borrow laptop running Ubuntu 8.04, so obviously TextMate has been out of the question. While the machine is powerful enough to run Eclipse (thus RadRails) or NetBeans, I wanted something simple and quick. As it turns out, Ubuntu 8.04’s Gnome 2.22 comes with gedit, which has a couple of pretty simple plugins that will make use for Rails development a little easier, but it needs a tiny final push to round it off.

First off, pop open the gedit preferences (the Edit menu, then Preferences). For programming basics you’ll want to turn on Display line numbers on the first preferences tab (under View), otherwise when you get Rails errors you won’t be able to find where they were. The next small thing worth doing is the Rails convention of using a tab width of 2 and inserting spaces instead of tabs, which you’ll find on the Editor section - oh, you’ll also want to Enable automatic indentation otherwise you’ll drive yourself crazy. One other small thing I do here is on the Fonts & Colors section I select the Oblivion color scheme, I find the darker background with the colored text to be easier on the eyes.

The fun really begins when you go to the Plugins tab, you’ll want to activate the File Browser Pane, Indent Lines, Snippets and Tag List plugins, but for good measure I also activated Change Case, Insert Date/Time, Modelines, Sort and Spell Checker, though you can skip those if you want.

At this point you’ll be able to browse through the file pane, find your project, then double-click on the main directory to turn the file pane’s focus on just your project, making it behave kinda like TextMate. You’ll also get syntax highlighting on all .rb files, which is all controllers and models.

However, there’s still something missing - no syntax highlighting on rake, ERb or RJS files - lets fix that. The rather simple fix involves tweaking some core Gnome files in the /usr/share/gtksourceview-2.0/language-specs directory to add detection for these extra files. So, in order to do this, pop into terminal and run the following commands:

sudo nano /usr/share/gtksourceview-2.0/language-specs/ruby.lang

Once the editor shows up, after completing the usual sudo login process, go down to the line that says:

<property name="globs">*.rb</property>

and change it to:

<property name="globs">*.rb;*.rake;*.rjs</property>

Next off:

sudo nano /usr/share/gtksourceview-2.0/language-specs/html.lang

Once again, search for the line that says:

<property name="globs">*..html;*.htm</property>

and change it to:

<property name="globs">*.html;*.htm;*.erb;*.rhtml</property>

And that’s all there is to it. Enjoy.

Share this post

In the past importing Gmail contacts was a bit of a hassle. One of the previous options was to use the Contacts gem found at RubyForge. However, now that the Google Contacts API has been released, it offers a more secure (and hopefully reliable) way to retrieve contacts. The Contacts API allows redirecting and authenticating users through Google, instead of forcing them enter their Gmail password into a third party application. Here is a quick tutorial to get up and running in ruby on rails with the Gmail Contacts API.

First, you need to register your domain with Google. This can be as easy as uploading a temporary file to your domain’s root directory to verify control of the domain. The steps for doing this are clearly outlined at Registration for Web-Based Applications.

Once you’ve verified control of the domain with google, start making your requests! Grabbing the contacts is essentially a three step process:

  • Initiate the authentication with Gmail. Send your user over to enter their credentials, after which Google passes back an AuthSub token valid for one request.
  • Send back the one-time AuthSub token and exchange it for a long-lived token valid for multiple requests.
  • Use this second token to make requests to the Gmail Contacts API and import user’s Gmail contacts.

    More detailed steps on how Google Authentication process works can be found at Authentication for Web Applications

Now lets visit the three steps above in more detail, and implement importing gmail contacts using ruby on rails!

1. First redirect your users to authenticate with Gmail and request a one-time use AuthSub token.

# initiate authentication w/ gmail
  #
  # create url with url-encoded params to initiate connection with contacts api
  #
  # next - The URL of the page that Google should redirect the user to after authentication.
  # scope - Indicates that the application is requesting a token to access contacts feeds. 
  # secure - Indicates whether the client is requesting a secure token.
  # session - Indicates whether the token returned can be exchanged for a multi-use (session) token.
  #  
  next_param = "http%3A%2F%2Fwww.example.com%2F"
  scope_param = "http%3A%2F%2Fwww.google.com%2Fm8%2Ffeeds%2F"
  secure_param = "0"
  session_param = "1"
  root_url = "https://www.google.com/accounts/AuthSubRequest"
  query_string = "?scope=#{scope_param}&session=#{session_param}&secure=#{secure_param}&next=#{next_param}"
  redirect_to root_url + query_string

2. Trade your single-use token for the all powerful AuthSub session token.

  require 'net/http'
  require 'net/https'
 
  token = params[:token] # received the single-use authsub token, exchange for authsub session token
 
  http = Net::HTTP.new('www.google.com', 443)
  http.use_ssl = true
  path = '/accounts/AuthSubSessionToken'
  headers = {'Authorization' => "AuthSubtoken=\"#{token}\""}
  resp, data = http.get(path, headers)
 
  if resp.code == "200" 
    token = ''
    data.split.each do |str|
      if not (str =~ /Token=/).nil?
        token = str.gsub(/Token=/, '')   
      end
    end
    redirect_to "http://www.example.com/?token=#{token}"
  else  
    redirect_to "http://www.example.com/"
  end

Note: There’s probably a better way to grab the above token from the response, if anyone would like to suggest a refactoring here please feel free . . .

3. Finally, grab your buddies!

# GET http://www.google.com/m8/feeds/contacts/default/base
require 'net/http'
require 'rexml/document'      
 
http = Net::HTTP.new('www.google.com', 80)
# by default Google returns 50? contacts at a time.  Set max-results to very high number
# in order to retrieve more contacts
path = "/m8/feeds/contacts/default/base?max-results=10000"
headers = {'Authorization' => "AuthSubtoken=\"#{authsub_token}\""}
resp, data = http.get(path, headers)
 
# extract the name and email address from the response data
xml = REXML::Document.new(data)
contacts = []
xml.elements.each('//entry') do |entry|
  person = {}
  person['name'] = entry.elements['title'].text
 
  gd_email = entry.elements['gd:email']
  person['email'] = gd_email.attributes['address'] if gd_email
 
  contacts << person
end

Hopefully that should help get you started on the right track. The Google Contacts API allows retrieval of other information besides simply name and email address. I’d be interested in hearing what else is everyone using/doing with this API?

Share this post

Nominate a Ruby Hero

By: Robert Dempsey | Tags:

Ruby Heroes

Many in the Ruby/Rails communities contribute much and get little to no recognition. No longer! Nominate those you think deserve recognition for their contributions to the Ruby and Rails communities.

Share this post

Recently I needed an application to be able to connect to a SQL Server database and import data into MySQL. After reading a number of different articles on the easiest way to accomplish this with each one being different and still not letting me accomplish my connection, I figured I would run through the steps that I used to make Rails work with SQL Server.

First off, I had to install the active record SQL Server gem.

install activerecord-sqlserver-adapter—source=http://gems.rubyonrails.org

Next, get the latest source distribution of Ruby-DBI from: http://rubyforge.org/projects/ruby-dbi/ and copy the file:

lib/dbd/ADO.rb

to:

X:/ruby/lib/ruby/site_ruby/1.8/DBD/ADO/ADO.rb

Then in the your config/database.yml file place:

sql_server_database_name:
adapter: sqlserver
database: database_name
host: server_name or local_machine_name
username: user_name
password: your_pw_here

user_name has to be a valid login for the SQL Server DB that has connect and select permissions

Lastly, place in any model that is going to need to establish a connection to SQL Server:

establish_connection :sql_server_database_name

It is that simple. Unfortunately, I never found a set of instructions on accomplishing this that worked for me, I had to take a number of examples and through trial and error, find out what combination worked. Hope this helps.

Share this post

Phusion, the Computer Science Company, released Phusion Passenger, a mod_rails for Apache which makes deployments of Rails applications easier. Passenger brings the PHP-style of deployment to Rails, upload their latest code and go. The Phusion site says that Passenger will automatically monitor Rails server processes thus lowering the need for systems administration. There are two flavors of license, free and enterprise. Install is super easy, and there is a video available along with a host of documentation.

Phusion Passenger does seem to lower the bar for deployment. At the same time, it increases the need to ensure that when you are ready to deploy, you have the latest code checked out from subversion ready to deploy. It also seems to require either the changing of a file (tmp/restart.txt) or a restart of Apache once you upload the latest. A quick perusal of the user documentation didn’t mention migrations, one of (IMO) the biggest strengths of Rails.

If anyone has experience deploying an application using Phusion Passenger please let us know how migrations are handled. We’ll be testing it out 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

New Virtual Hosting Solution Designed Specifically for Rails Applications Delivers 99.9% Uptime

WINTER PARK, FL (March 27, 2008)…Web development innovator Atlantic Dominion Solutions (ADS) today announced the introduction of a fully managed hosting solution designed specifically for Ruby on Rails deployments – ADS Mantis Hosting. Intended to provide the reliable stability and support lacking from some other virtual hosting options, the service provides complete hosting capabilities for Rails applications on virtual servers that ADS customizes to meet the unique needs of each application.

“We were hearing from a lot of people that they were frustrated by the instability of their virtual hosting service,” said ADS Project Director, Robert Dempsey. “It doesn’t matter how great your web app is if it’s down. So we set out to solve the problem ourselves, by delivering the flexibility and scalability of virtual hosting without the uncertainty around downtime, and with the added benefit of full support and management. I think ADS Mantis Hosting is well equipped to achieve that objective.”

To help reach that goal, ADS partnered with Rails Machine for its high-quality hardware and network infrastructure. The combination of fully managed hosting from ADS and a reliable Rails Machine platform allows ADS Mantis Hosting to deliver 99.9% uptime and guarantee system resources are available whenever the application needs them.

“Partnering with Rails Machine allowed us to give our clients the reliability of rock-solid, proven hosting,” said Dempsey. “Their solutions are extremely efficient and provide the consistent uptime and stability needed to ensure peak performance for our clients’ Rails apps.”

Rails Machine’s CTO Dan Benjamin echoed Dempsey’s enthusiasm and saw the partnership as a great opportunity to collaborate with other forward-thinking developers to come up with solutions that benefit everyone using Ruby on Rails.

“We’re excited about partnering with a leading development company like ADS,” said Dan Benjamin, Rails Machine CTO. “ADS Mantis Hosting really takes advantage of our infrastructure to deliver our common goal - to make Ruby on Rails faster and easier to deploy.”

Ultimately, Dempsey sees ADS Mantis Hosting allowing organizations to maintain sophisticated web applications without any significant commitment of time and resources, allowing them to focus solely on their core business.

“The scalability offered by virtual hosting is obviously fantastic,” said Dempsey. “But at the end of the day what’s most important is performance and reliability, and it can be hard to find internal resources to dedicate to monitoring and managing your application. With ADS Mantis Hosting, our clients can have us do all the work for them and not waste a second worrying about the status of their web app.”

ADS Mantis Hosting is available for all Ruby on Rails deployments. For more information about ADS Mantis Hosting, visit http://www.techcfl.com/ads-mantis-hosting.

About Atlantic Dominion Solutions

ADS is a leading-edge web development firm that specializes in using Ruby on Rails to build advanced, scalable, database-backed applications for organizations of all sizes. Based on custom requirements, ADS creates forward-thinking and user-focused applications that can be deployed quickly, scaled easily, and maintained with minimal time or effort. ADS is a vanguard in enhancing Rails platforms with Amazon Web Services and, along with visionary web applications, ADS also provides data warehousing and data mining, graphic and interactive design, and business and technical consulting. For more information, visit www.techcfl.com.

About Rails Machine

Rails Machine provides web hosting, software, and support for commercial Ruby on Rails application deployments. Its principal clients are professional Ruby on Rails developers using pre-configured servers featuring high quality hardware and network infrastructure. They also offer server configuration tools for simple and high quality solutions for deploying applications in either hosted or internal corporate environments. For additional information, please visit www.railsmachine.com.

Share this post

TextMate Tip: HTML Tags

By: Chris Kaukis | Tags:

Have you ever just wanted to select some text and wrap it in a tag instead of jumping to the beginning and end of the lines? Or perhaps you get tired of remembering to close your tags as you go and you wish it was done for you. Both are possible, you just have to know the right keystrokes.

In any HTML editing mode in TextMate (HTML, HTML (Rails), etc) try the following then start typing:

Shift + ctrl + W

You can also select text you want to wrap in the tag.

Click here to view the screencast and see an example

In the screencast, I also used another nice little shortcut.

 + return

This will do a carriage return to the next line starting at the end of the current line, not at the current cursor location.

The Fine Print: It’s my first screencast, it might suck.

Share this post