Ruby on Rails

Ruby on Rails 3.0 Conversion

Posted in Solutions on Nov 30. Tags: , , , ,

Finally, after a few weeks learning the actual ropes of Ruby on Rails 3.0, I’ve completed the upgrade of the http://envirochase.com/“>envirochase.com web site! It has been a great lesson in the new intricacies of the way queries/namescopes are being handled.

It’s also a lot faster. Orders of magnitude faster, in fact, than the old version (1.0). I’m very happy with it! The project has become proof to the owner that This is the way to go after all – a staged complete conversion of all sites to their shiny new Mac OS X Snow Leopard Server running both the database and the web application(s).

 

Online Job Cards

Posted in Slider Item, Solutions on Jul 30. Tags: , , , , , ,

The system is designed to improve response times when operations are flowing smoothly so that issues can be resolved faster when they occur. Drivers are able to view and update their run sheet as soon as the job is done using their data enabled mobile devices. Jobs are displayed in the order of importance and can be marked as having been done or having issues that need to be resolved.

The Online Job Cards system is integrated directly into the existing legacy booking system, providing a fast reliable link between the drivers performing the services and the operations staff overseeing each division. General job status is provided visually using colour coding on the operations mangement screens in real time. When a new job is allocated to a driver, it will appear on their mobile device as soon as they refresh their Online Job Card.

Another excellent situation for data enabled mobile devices. Further updates are planned, including obtaining customer proof-of-completion signatures for invoicing purposes and using Location Services to pinpoint where the jobs are being performed.

This solution uses:

  • Microsoft SQL Server
  • Ruby on Rails
  • Telstra NextG
  • HTML4+ enabled web browser (iPhone/Android/iPad)

openssl, ruby, rails, mysql and SHA256 errors

Posted in blog on Feb 19. Tags: ,

In the interests of not having to re-figure out how to install the above systems on my mac os (tiger 10.5.8) I am going to post the commands that I eventually used to get the damn thing to, essentially, recognise the new version of openssl I installed to be able to use the SHA256 digest method so I could talk to facebook correctly.

3.days.ago everything went pear shaped.

Prior to running this:

  • Install http://mxcl.github.com/homebrew/“>homebrew (to make installing openssl “easier” but really could be replaced next time with a curl/tar/configure/make set).
  • Make sure your $PATH lists /usr/local/bin before /usr/bin, as outlined on http://hivelogic.com/articles/ruby-rails-leopard“>hivelogic (most of these commands come from there).
  • Slap yourself once (again) for forgetting, 4.months.ago, to turn your Time Machine back on.


brew install openssl
mkdir /usr/local/src
cd /usr/local/src
curl -O ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.7-p330.tar.gz
tar xzvf ruby-1.8.7-p330.tar.gz
cd ruby-1.8.7-p330
./configure --enable-shared --enable-pthread CFLAGS=-D_XOPEN_SOURCE=1 --with-openssl-dir=/usr/local/Cellar/openssl/0.9.8o/
make
sudo make install
cd ..
curl -O http://rubyforge.iasi.roedu.net/files/rubygems/rubygems-1.3.4.tgz
tar xzvf rubygems-1.3.4.tgz
cd rubygems-1.3.4
sudo /usr/local/bin/ruby setup.rb
cd ..
sudo gem install rails
sudo gem install mongrel
sudo gem install capistrano
sudo gem install mysql -- --with-mysql-dir=/usr/local/mysql

And that should just about do it. Check it’s all working (specifically the SHA256 part) with this command

ruby -ropenssl -e 'p OpenSSL::Digest::Digest.new("sha256")'

which should not return any errors. That being the point of the entire exercise.

simple auto complete text field

Posted in blog on Mar 26. Tags: , , , ,

I have been working on understanding the text_field_with_auto_complete functionality in Ruby on Rails for a project I am currently working on. There seems to be two written tutorials on the subject and they were a little confusing. Here is my attempt to be more specific.

Goal:

While editing an address record I want to show the user a short list of available suburbs that match what they have begun typing into he text box; and allow them to pick the one they want to use. When they save the record, I only want to store the ID of the suburb they typed in, not the actual text.

Solution:

Install the auto_complete gem:

ruby script/plugin install git://github.com/rails/auto_complete.git

This didn’t work on the windows system I was using, so I ended up having to grab the ZIP file and copy the contents to the ‘vendor/plugins/auto_complete’ folder the above command created.

First of all add to the site.rb model so we can refer to the suburb_name as if it was a field in the sites table:

def <span style="color: #ff00ff;">suburb_name</span>
  <span style="color: #00ccff;">suburb.name</span> if <span style="color: #ff6600;">suburb_id</span>
end

def <span style="color: #ff00ff;">suburb_name</span>=(value)
  self.<span style="color: #ff6600;">suburb_id</span> = Suburb.find_by_name(<span style="color: #ff0000;">value.split(',')[0]</span>).<span style="color: #000000;">id</span> unless value.blank?
end

Update the sites/edit.html.erb view to do the auto_complete markup:

<p>
  <%= f.label :<span style="color: #ff6600;">suburb </span>%><br />
  <%= text_field_with_auto_complete <span style="color: #993366;">:site</span>, :<span style="color: #ff00ff;">suburb_name</span>, {}, :skip_style => false %>
</p>

Add an action to the sites_controller.rb so the auto_complete call(s) can get the short list:

def auto_complete_for_<span style="color: #cc99ff;">site</span>_<span style="color: #ff00ff;">suburb_name</span>()  
  <span style="color: #0000ff;">@suburbs</span> = Suburb.find(:all , :conditions=> "<span style="color: #33cccc;">name </span>like '%"+params[<span style="color: #993366;"><span style="color: #000000;">:</span><span style="color: #cc99ff;">site</span></span>][:<span style="color: #ff00ff;">suburb_name</span>].upcase+"%' and we_deliver_to=1")  
  render :partial => '<span style="color: #99cc00;">auto_complete_</span><span style="color: #ff00ff;">suburb_name</span>'
end

Finally, create the _auto_complete_suburb_name.html.erb partial in the views/sites folder, the smallest form of which is like this

<ul><% for suburb in <span style="color: #0000ff;">@suburbs</span> do %><li><%=h <span style="color: #00ccff;">suburb.name</span> %><span style="color: #ff0000;">, </span><%=h suburb.postcode %></li><% end %></ul>

Important stuff you should know

  • I have added highlighting to illustrate the important connections between names as you move between view/model/controller. If you change one, you need to make the same change in every other occurence.
  • The suburbs table has no duplicates across the [name] field and no commas in any name value.
  • The COMMA in the partial is vitally important, I use it to tell the difference between the name value and the rest of the information that I don’t care about (the postcode). Use your own unique seperator if you have comma’s in your data.
  • No spaces in the _auto_complete_suburb_name partial, if you format it nicely your selected result will have lots of extra spaces (you’ll see what I mean)
  • There is no error checking in this. If the user types in a junk suburb the current code will not handle it gracefully.

Online ordering of waste services

Posted in Solutions on Nov 18. Tags: , ,

Brief

The client wants to be able to offer members of the public the ability to order and pay for bin services via the internet (without applying for an account). The process must be very simple and understandable because no human interaction will take place prior to the order being placed. The system must ensure that; the correct pricing is used; the service address is located within a servicable area; the customer’s placement instructions are not overly complex; and that the payment has been received prior to accepting the booking.

The client would also like to offer Account Customers (“Members”) the ability to order and cancel services via the internet. Members can log in to view and update their outstanding service orders. The Member’s area will show all the current locations and the various services we provide at each one. Any complex enquiries will be handled through the call centre.

The solution must keep in line with the existing web site’s look and feel. The solution needs to integrate seamlessly with the existing (proprietory) business database system and its business rules.

Solution

A step-by-step wizard was created for the creditcard (public) ordering function. The steps are designed to flow logically from one to the next while obtaining the required information quickly so that each subsequent step is as concise at possible. The information funnel looks like this: Location > Product > Payment > Confirmation > Receipt.

A Member’s area was also created, using standard authentication techniques, that provides a multi-tiered drill down navigation system. The top level provides a listing of account details coupled with the (paginated) list of active sites. Clicking on any site will display more details such as any outstanding orders for bin services and any active contractual arrangements. Members can order new services using a wizard similar to the public one, except that the location and payment steps are not necessary. Members can also cancel any services that meet the cancellation requirements.

 

This solution uses:

  • Microsoft SQL Server
  • Ruby on Rails