Git Setup

This post has been moved to here

Mongrel Rails on Windows 7

I’ve been having a bit of trouble getting Webrick running properly on Ubuntu and Windows; and the resolution… ??? I don’t know, but the suggestions are to try Mongrel, which though a solution is a bit annoying as Webrick is there ready to go…

Installing Mongrel on Windows 7 was rather easy though; it involved

gem install mongrel

Then just navigating to the directory with the rails application in it and typing:

mongrel_rails start

CTRL-C stops the process.

The instructions here for installing the win32-service didn’t work, but this did help… So i ran the following command:

gem install win32-service –platform x86-mswin32

… and it installed. Now we need to install mongrel_service

gem install mongrel_service

… which fails… and i still need to resolve this :(

ASP.NET MVC: Constructing UrlHelper

I needed to have a class external to the controller’s and views that could generate a correctly formed Url using the UrlHelper.

I found this question on Stackoverflow which helped me with a solution. The solution was as follows:

HttpContextWrapper httpContextWrapper =
    new HttpContextWrapper(HttpContext.Current);

UrlHelper urlHelper = new UrlHelper(
    new RequestContext(
        httpContextWrapper, 
        new RouteData()));

I previously got confused about the RouteData object, but it seems (unless I’m mistaken) to essentially be route values, which in this case i don’t need… Not sure on that though!

As constructed above, the UrlHelper is able to take the RequestContext and get all the registered routes and therefore generate a correctly structured url when you call Action etc.

JavaScript: calling a method and changing what “this” means

This post has been moved here

jQuery.ui dialog: adding classe to buttons

Had this question come up at work and found a good answer on stackoverflow here. It basically involves handling the open event, finding the buttons and applying a style to them.

Firstly a simple bit of html:

<a id="to_dialog_a" href="javascript:void(0);">click me</a>
<div id="to_dialog" style="border: 1px solid gold; background-color: #336699"></div>

And here is some javascript to wire it up. In the example below I have done things a little differently as the application we are developing needs to be localized; so i used the button index.

Note: This example doesn’t have any jquery.ui css to deal with.

A whole example html file is located here

        $(document).ready(function() {
            $("#to_dialog_a").click(function() {
                $("#to_dialog").dialog("open");
            });
            $("#to_dialog").dialog({
                autoOpen: false,
                buttons : {
                    ok: function() {
                        alert("you clicked me!");
                    },
                    what: function() {
                        alert("you clicked me!");
                    },
                    cancel: function() {
                        alert("you clicked me!");
                    }
                }
                ,
                open: function(event, ui) {
                    // Get the dialog
                    var dialog = $(event.target).parents(".ui-dialog.ui-widget");

                    // Get the buttons
                    var buttons = dialog.find(".ui-dialog-buttonpane").find("button");

                    var okButton = buttons[0];
                    var whatButton = buttons[1];
                    var cancelButton = buttons[2];

                    // Add class to the buttons
                    // Add class to the buttons
                    $(okButton).addClass("primary");
                    $(whatButton).addClass("secondary");
                    $(cancelButton).addClass("thirdary");
                }
            });
        });

Send Secure Email Via Gmail in Ruby 1.8.7

This post has been moved here

Disabling selection of a section

Found this little gem while trying to prevent selection behind the jQuery.treeview controll.

onselectstart="return false;" style="-moz-user-select: none;"

This worked for me on Chrome, IE 8, and FireFox 3.6.

Found this tidbit here.

Update: 2010-07-05 – Found this interesting extension to jQuery also. Note the replies also as they may be of use.

Follow

Get every new post delivered to your Inbox.