house9

random code and what not

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.



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’
collection_select(:product,
:category_id,
Category.all,
:id,
:title,
{:prompt => true}
)

collection_select(:product,
:category_id,
Category.all,
:id,
:title,
{: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

Comments

Tarnschaf
Thank you!
Eric Jones
Thank you! I was trying to figure out why I couldn't get the prompt to show up, now I know why. I was editing an existing record.
Julien
Thank you!! I was scratching my head to find how i could force "prompt" message in collection_select!
danieltsadok
Thanks - I was wondering what the difference was…

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.

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


Comments

muck_a_luck
You are AWESOME!!!! :D

‘file version’ is not in the normal ‘major.minor.build.revision’ 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 ‘2.7.1.65559’ specified for the ‘file version’ is not in the normal ‘major.minor.build.revision’ 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 2.7.1.65559 we are using the version 2.7.1.5559

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

Get Filenames and Database names from MSSQL

I was doing some clean up on one of our database servers; we have many databases created with backup/restore for testing purposes I was checking for the largest ldf files and making sure those databases were in simple mode and then shirking the data files, there were a few files I could not match to the databases because the mdf and ldf file names were different from the actual database file name - found the following queries using a few google searches







jqueryUI effect error with Google Chrome and Safari

Ran into a strange issue using jqueryUI highlight effect, the issue only occurred with Webkit browsers (Google Chrome and Safari) and only when I was manipulating the background property of the element that was being highlighted.

Using a slightly modified version of the demo. I tweak the background image before applying the highlight effect

$("#highlight").click(function() {
$(this).css("background", "url(some_image.png) no-repeat");
$(this).effect("highlight");
});
This resulted in the highlight appearing but not going away. Then checking it in the debugger the following javascript error was being generated - “Uncaught TypeError: Cannot read property ‘0’ of undefined,” Changing the background manipulation to the following fixed the issue.

$(this).css("background-image", "url(some_image.png)");
$(this).css("background-repeat", "no-repeat");
$(this).effect("highlight");

Update 2009-03-06: You also need to make sure that if there is an existing style on the element being highlighted it is using the more verbose style tags of background-image and background-repeat or the same error will be encountered

Comments

Wesley
Thank you for your post. This has solved a similar jQueryUI problem for me on Chrome. I'm also aware now that it may be safer to use verbose background styles when dealing with Chrome and jQuery.
Tim Stevens
just had the same problem.

was trying to highlight a table row that had been newly created.

solved the problem by highlighting each child cell instead

//tbody is the body of a table with a header and a footer. I just want to highlight the first row
//I use row.find rather than row.children in case there are embedded tables

tbody.find("tr:first").find("td").effect("highlight", {}, 1000);


This didn't exhibit the same behaviour as just highlighting the row.

use jquery to disable a button when clicked

jquery is such a great javascript library, the more I use it the more I like it



NOTE: the above code snippets are untested - cut, pasted and modified from real code that was tested (and worked!)