The blog has moved to ... Many google searches point here so I am leaving it operational, but there will be no new posts.

Saturday, April 25, 2009

Strange behavior with Rails find_or_initialize_by_id and Postgresql

The following code sample worked as I would expect when using MySql database - when the :widget_id is 0 it creates a new record with an id of 1; but after switching to Postgresql it was inserting a record into the database with an id of 0 (zero)?

Note: params[:widget_id] does have a value of 0 (zero) when I want to generate a new record vs an actual value when doing an edit. This is a non-standard rails form, I did not experience any issues with a standard new/create view/action scenario.

Thursday, April 23, 2009

PGError: ERROR: invalid byte sequence for encoding "UTF8": 0xa7 (ActiveRecord::StatementInvalid)

Now that Oracle is buying Sun I am switching from MySql to Postgresql

Ran into the following error with my rails application after switching over

PGError: ERROR: invalid byte sequence for encoding "UTF8": 0xa7 (ActiveRecord::StatementInvalid)
HINT: This error can also happen if the byte sequence does not match the encoding expected by the server, which is controlled by "client_encoding".
Found a work-around, check it out here

PGError: ERROR: invalid byte sequence for encoding "UTF8": 0xa7 (ActiveRecord::StatementInvalid)

Working on a rails application and have decided to make the switch from MySql to Postgresql; ran into a few minor issues along the way and one really annoying and unexpected issue

PGError: ERROR: invalid byte sequence for encoding "UTF8": 0xa7 (ActiveRecord::StatementInvalid)
HINT: This error can also happen if the byte sequence does not match the encoding expected by the server, which is controlled by "client_encoding".

The above error was being generated when I was trying to save model objects that had their string and text attributes assigned from data that had been scrapped using http with scRUBYt. After searching on Google the only 'work-around' I found was to use base64 encode and decode when reading and writing to these model attributes / database columns

Given the following migration

Our model before and then after applying the work-around


Sunday, April 12, 2009

rails collection_select to prompt or include_blank?

Well I just wasted a bit of time but learned something in the end. When working with the rails form helper collection_select you might be interested in the difference between the prompt option and include_blank? option

include_blank will always create an option tag, prompt will only create an option tag when creating a new record - in most cases I prefer include_blank

both take either a boolean or a string, if true is passed then include_blank will create an option with no display text and prompt defaults to the display text of 'Please Select'
{:prompt => true}

{:include_blank => 'Please Select'}
both of these result in the same html, but the first one will not include the 'Please Select' option when you return to edit the previously created Product

See also

Saturday, April 11, 2009

accesskey attribute on the select tag is not valid?

Was just running some validation on a html form and it failed with the following error
"Invalid markup: line 68: Attribute "accesskey" exists, but can not be used for this element."

From w3c spec - "The following elements support the accesskey attribute: A, AREA, BUTTON, INPUT, LABEL, and LEGEND, and TEXTAREA."

I have no idea why input and textarea would be supported but not select? this seems like a mistake? At least there is an easy work around - apply the accesskey attribute to the label tag that references the select menu.

Thursday, April 9, 2009

IE8 multiple cookies for the same site

Internet Explorer 8 is here - oh joy....

As a web application developer I spend a lot of time logging into sites as different users and prefer to be able to toggle back and forth between multiple instances of a browser maintaining the separate sessions in each instance. With IE 7 this was not an issue as long as IE was launched from the toolbar. In IE 8 sessions are shared by default, once again a Google search delivers the goods!

This post explains the -no-merge switch

as easy as Start -> Run -> iexplore.exe -nomerge

FireFox has a similar issue, but the only work around I know of with FireFox is to create separate profiles, see this post - FireFox and multiple cookies for the same site

'file version' is not in the normal '' format

At work we use TFS for source control and NAnt for building our application, yesterday our NAnt build started failing with the following error message "Assembly generation The version '' specified for the 'file version' is not in the normal '' format"

After a quick Google search it turns out that each segment in a .net assembly cannot be larger then 65534. We use the TFS changeset for the revision segment but this will no longer work for us as we are now beyond changeset 65534 - doh! As a work around we are now using only the last 4 digits of the changeset, so instead of we are using the version

this required a small change to the Nant build script
  • the update is here
  • and the original is here
this version constraint is documented here

UPDATE: NAnt build with TFS changeset as revision number

this is a small revision to a previous post NAnt build with TFS changeset as revision number

apparently there is a limitation on the size of the number used in each segment of a .net assembly version so this is a slight update to the c# code that gets the latest changeset from TFS - changes start at "if(latestChangsetId > 65534)"

see also AssemblyVersion - BuildNo Limitation