Book Review: Mobile First by Luke Wroblewski

If you’ve not heard of A book Apart they are brilliant at providing short to the moment guides aimed at people without the time to spend digging around through reams of pages. Just perfect for the train!

Luke Wroblewski doesn’t disappoint in this short guide on Mobile First for designers. Reading through this guide offers a wealth of advice, every second sentence it felt like another simple statement resonating within me. Here are just a few highlights (really) I particularly enjoyed, but for a few quid go and get the whole book:

Continue reading

Switching a rails app from mySQL 5.1 to postgresql 8.4

Switching a rails app across to postgresql became a necessity recently due to the range of licencing and ownership considerations which have affected mySQL recently. Not wanting to be restricted in some way in how I utilise my app I decided to investigate using the popular opensource postgresql database.

Continue reading

Quick Tip: How to fix ‘rake/rdoctask’ is deprecated. use rdoc/task instead

If you’ve recently found rails complaining about the following:

rake/rdoctask is deprecated. Use rdoc/task instead (in RDoc 2.4.2+)

then open up your rakefile.rb and change

require 'rake/rdoctask'

to look like this:

require 'rdoc/task'

and remember to add the following to your Gemfile


group :development do
gem 'rdoc'

end

You may need to run the following on the command line to freshen your gems

sudo bundle install

Rails selection lists

Problem: I’ve got the need to have a list of options presented in a drop down list but I really don’t mind them being hard coded somewhere (if I did I’d stuff them in a database table).

Fix: Easy I can add an array of arrays to my model file and them pull them through to the view. In each sub-array the first element in the name displayed, the second is that submitted with the request.

Example: In the model for my bookings I add booking_status

class Booking < ActiveRecord::Base

  BOOKING_STATUS = [
    ['booked', 'booked'],
    ['request', 'request'],
    ['pending', 'pending'],
    ['approved', 'approved'],
    ['not-approved', 'not_approved'],
    ['other', 'other'] ]

end

In the view I can then include a selection tag which uses each of these items

<%= f.select :status, Booking::BOOKING_STATUS %>

Rails rapid prototyping – partials

Rails script generators enable true prototyping from the command line. The simplicity of being able to generate a complete working application within a few commands is wonderful. However I often find that I’m spending time to ensure some very simple basics are better than the out of the box offering.

Yes I know I prototyping, yes I know I’m going to through it away at the end of the day but still there is no need for not making effective use of partials in forms.

Partials within forms makes sure functionality is rapidly updated in both the new and edit actions.

So typically I like to convert:

<h1>Editing booking</h1>

<% form_for(@booking) do |f| %>
  <%= f.error_messages %>

  <p>
    <%= f.label :event_id %><br />
    <%= f.text_field :event_id %>
  </p>
  <p>
    <%= f.label :user_id %><br />
    <%= f.text_field :user_id %>
  </p>
  <p>
    <%= f.label :status %><br />
    <%= f.text_field :status %>
  </p>
  <p>
    <%= f.submit 'Update' %>
  </p>
<% end %>

to something which makes much more sense like:

<h1>Editing booking</h1>

<% form_for(@booking) do |f| %>
  <%= render :partial => 'form', :locals => { :f => f } %>
  <p>
    <%= f.submit 'Update' %>
  </p>
<% end %>

I’d encourage you to do the same and see how it saves you one more piece of hassle. And of course if your using text mate remember ctrl+shift+H will create the partial for you.

Apache – Name Virtual Host errors

For some time now apache has been bugging me that there is a configuration issue with my virtual hosts, so I decided to find out what the issue was and try to resolve it. As it happens the fix was easy but not well documented.
Issue:
[warn] NameVirtualHost *:80 has no VirtualHosts
Resolution:
You can resolve this by ensuring that you virtual hosts are configured correctly. To do this you should have a NameVirtualHost for each of your ports and then be using ServerName within each virtualhost. By configuring apache this way you allow it to correctly interpret requests for different virtual hosts on the same IP Address.
Example:
In my apache2.conf file I have the following declaration
NameVirtualHost *:80
And then each of the virtual hosts is configured:
<VirtualHost *:80>
RailsEnv beta
ServerName my-app.redjamjar.net
DocumentRoot /home/rails/beta/my-app/current/public
<Directory “/home/rails/beta/my-app/current/public”>
allow from all
AllowOverride All
</Directory>
</VirtualHost>

Integration – how to plan for the unknown

No one has ever said integration of one system with another is straight forward. But does it always need to be a surprise a minute roller coaster ride? In a recent and slightly challenging (read evolving) integration projects I devised a simple set of rules:

Action Plan:

  1. Identify the unknowns
    How? Start simply with broad questions. Don’t be too quick to get into the detail as this will be the natural tendency. At this stage understand nothing about the detail but fully comprehending the end user environment or capabilities will give you a greater barometer for detecting where the unknowns are essential or not.
  2. Questions everything, assume nothing
    I’ve tripped over this many times, combined with one this is probably the largest probably when scoping, initiating or specify an integration piece of work. I find Excel is my friend in this situation, I can capture questions and responses as the knowledge flows
  3. Seek documentation but don’t rely on it.
    Documentation in what ever form is usually well intentioned, but out of date, inaccurate or just plain wrong. Typically the documentation will look grand ‘Technical Specification for X.Y.Z version 1.2′ however what tends to happen is that was written at the outset before a line of code had been written – ask yourself when you last went back and updated a specification at the end of project, yet you want to make key integration decisions based on it?
  4. Get a setup of the system as close as possible to the real environment for use during development, verification testing and UAT
  5. Commit, integrate and test regularly. Really if your not doing this forget it
  6. Use real data not ‘lorem ipsum’ or ‘test account 1′
    Demand this especially if you have translation or localisation considerations to consider.
  7. Allow your/encourage your client to come and inspect your work – they may see things your developer mind over looked.
    Coming from a developer mind I’m always surprised how easy it is to be lulled by our perspective on systems.
  8. Testing
    Even with all the automated testing, eyeballs and code reviews I’m still amazed by how often I come across developers who see it as acceptable to ship code from their development computer to a production environment without any testing.

Have I overlooked anything you find works best for you? Let me have your comments and I’ll add them in.

Secure Copy How to

Heres a rough and ready introduction to using the power of SSH to perform a secure copy of a file or directory between computers.

> scp 

usage: scp [-1246BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file]
           [-l limit] [-o ssh_option] [-P port] [-S program]
           [[user@]host1:]file1 [...] [[user@]host2:]file2

So how does this matter for me well if you wanted to move a file from a server called Mojo.com to a server called Louis.com you’d enter

> scp file.txt my_login_name@louis.com:remote_directory

or if I want to copy a folder:

> scp -r my_login_name@louis.com:remote_directory my_files

Hope this helps.

By the way for those on Windows Penguinet has scp built in with a nice looking file browser/selection UI.

Rails localisation bug

I’ve just gone through the challenge of working out what was wrong with the following piece of code:

<% form_tag :controller => '/' do %>
				<%= t(:'txt.language') %> <%= select_tag("locale", options_for_select(LOCALES_AVAILABLE, I18n.locale), { :index => nil, :o nchange => 'this.form.submit()'}) %>
			<% end %>

Our client reported that on a signup page where they choose an alternative language it got redirected and they could never reach the page in their native language.

How can this happen you might ask?

Well the request includes some values within the url which are used as a key. Only if the key is valid is the controller allowed to complete the request. The issue is the combining of maintaining the key and switching the language.

As it happens its a very simple fix and was pointed out to me by Juliana.

<% form_tag :controller => request.request_uri do %>
				<%= t(:'txt.language') %> <%= select_tag("locale", options_for_select(LOCALES_AVAILABLE, I18n.locale), { :index => nil, :o nchange => 'this.form.submit()'}) %>
			<% end %>

In this fixed second example the alteration for the controller has been updated to direct the language selector to the controller of the current page. The documentation for this suggests that its broken on IIS (really should you be even trying to use this?) in fact I found that the source has had a significant amount of work go into it to work around the issue and even make it work on that webserver. Its a great little solution to ensure that the reloaded page is returned to the user in the state it was with the addition of the correct language.