On Blur Save with JRails In Place Editing

Jan 16, 2010

Code

0 Comments

I’ve been working on a Rails app recently where I used the excellent jrails_in_place_editing plugin to create a large number of in-place editing textfields. I used this in lieu of the Rails plugin because I removed Prototype completely from my app. I’m prone to do this because jQuery is so clearly better than Prototype. Please, Rails Core, replace this? I usually do this using the JRails plugin because it has all the built-in helpers written for jQuery — beautiful!

In any case, the jrails_in_place_editing plugin is quite wonderful, but limited in terms of the number of features it actually implements. The jQuery plugin it is based on has a load of more configurable features. I added in a few back for my needs, but there’s one basic functionality I was surprised to find missing: on-blur saving. Brandy suggested I needed this in my project, and I have to say she was very right — it makes editing a lot of fields so much easier for power users.

Doing this is very simple. All you need to do is add the following to /public/javascripts/jquery.inplace.js:

//ON BLUR SAVE functionality
original_element.children("form").children(".inplace_field").blur(function(){
	//put the original background color in
	original_element.css("background", settings.bg_out);

	var new_html = jQuery(this).parent().children(0).val();

	//set saving message
	if(settings.saving_image != ""){
		var saving_message = '<img src="' + settings.saving_image + '" alt="Saving..." />';
	} else {
		var saving_message = settings.saving_text;
	}

	//place the saving text/image in the original element
	original_element.html(saving_message);

	if(settings.params != ""){
		settings.params = "&" + settings.params;
	}

	if(settings.callback) {
		html = settings.callback(original_element.attr("id"), new_html, original_html, settings.params);
		editing = false;
		click_count = 0;
		if (html) {
			// put the newly updated info into the original element
			original_element.html(html || new_html);
		} else {
			// failure; put original back
			alert("Failed to save value: " + new_html);
			original_element.html(original_html);
		}
	} else if (settings.value_required && new_html == "") {
		editing = false;
		click_count = 0;
		original_element.html(original_html);
		alert("Error: You must enter a value to save this field");
	} else {
		jQuery.ajax({
			url: settings.url,
			type: "POST",
			data: settings.update_value + '=' + new_html + '&' + settings.element_id + '=' +
					original_element.attr("id") + settings.params +
					'&' + settings.original_html + '=' + original_html,
			dataType: "html",
			complete: function(request){
				editing = false;
				click_count = 0;
			},
			success: function(html){
				// if the text returned by the server is empty,
			// put a marker as text in the original element
				var new_text = html || settings.default_text;

				// put the newly updated info into the original element
				original_element.html(new_text);
				if (settings.success) settings.success(html, original_element);
			},
			error: function(request) {
				original_element.html(original_html);
				if (settings.error) settings.error(request, original_element);
			}
		});
	}

	return false;
});

Of course, if you use cacheing you’ll want to delete all.js and let Rails re-cache with the reflected changes. This code worked like a dream for me — hope it helps you too!

Learn Your Damn Homophones on Twitter

Jan 16, 2010

News

0 Comments

So, we’re on twitter now.

Hit us up with your suggestions, comments, complaints — whatever.

@homophone

Top Applications of 2009

Jan 8, 2010

Lists

0 Comments

Introduction

In the spirit of putting a close to 2009 and the coronation of a new decade, I’d like to present my list of top applications of 2009. I spend a vast majority of my time on the computer: my job, my education and my hobbies are all computer-based. There are a lot of applications I use both on the computer and in the cloud that are absolutely indispensable to me. It’s interesting to see how this list hasn’t really changed much since 2008. Some notable exceptions are my transition from Gmail to Mail.app, indie paid apps replacing free open-source alternatives and few new comers. Also, iPhone apps are a new medium I’m tracking as my iPhone has become absolutely necessary to everyday life. (Note that I’m tracking non-Apple apps. The standard apps will always take up a majority of the top 10 so that’s fairly useless, although I’d like to mention that my top 3 are SMS, Mail and Phone respectively.) I’d like to know what your top apps were—fire away in the comments. But, without further ado let me present my list.

Top 10 Computer-Based Applications

  1. Safari 4.0—by far my most used app.
  2. Adium
  3. Mail
  4. Dropbox—client app is as important as its cloud counterpart
  5. Textmate—hands down the best text editor ever
  6. Transmit—simply the best FTP client
  7. Sequel Pro—wonderful mysql interface; I simply couldn’t work without it
  8. Skype—useful for long-distance relationships
  9. Terminal
  10. iTunes

Honorable mentions: Things, Newsfire, Photoshop

Top 10 Cloud-based Applications

  1. Facebook
  2. Twitter
  3. Dropbox
  4. 2schedule
  5. Github
  6. Whatthemovie
  7. Google Wave
  8. Wordpress
  9. Are My Sites Up?
  10. Newstwit

Honorable mention: LinkedIn, Basecamp, Last.fm, LittleSnapper/Droplr/TinyGrab/Skitch

Top 10 iPhone Apps

  1. Facebook
  2. Tweetie
  3. Words with Friends
  4. Ego
  5. UrbanSpoon
  6. Chase (bank app)
  7. Tunnel
  8. Shazam
  9. Dropbox
  10. MetaSquares

Honorable mention: NYTimes, iDisk, AMSU Lite, LyricSift, NotAParkingSpot, RampChamp, Monopoly, Tumblr

Conclusion

There are a few interesting trends here. I’m curious to see if after tracking for additional years I’ll be able to extrapolate any useful information. In any case, what were your top apps of 2009? Do you have any that match me? Let me know in the comments.

Rails, Facebooker and Double Slashes in Resource Routes

Jan 7, 2010

Code

6 Comments

So, I’m working a Rails app and everything is going smoothly. I installed Facebooker (the plugin to interface with Facebook Connect) and got it integrated with my app’s user authentication in almost no time—perfect. But somehow between rails app and installing Facebooker, all of my stylesheet and javascript links broke (using, of course, the default javascript_include_tag and stylesheet_link_tag). The links now had a mysterious double slash after the host name (i.e., domain.tld//stylesheets/scaffold.css; domain.tld//javascripts/application.js). Truly odd. After scouring the internet and talking to some friends, no one could proffer any information on how to fix the issue. Evan and I spent a lot of frustration over this. Even stranger: the link tags worked as expected on the server in production and were only broken in development.

I stepped away from it and after a serious inspiration session from my muse, I solved the issue in five minutes. Seriously, it’s quite simple: in config/facebooker.yml, be sure that your callback_url does not have a trailing slash—in any environment. That’s it, problem solved.

Travelog

Dec 11, 2009

News

0 Comments

I started a tumblr as a little place to track my travels. I’m kicking it off with my trip to DC that starts tomorrow. You can follow it all here.

Drew Brees Quote: 11/30/09

Be where you’re supposed to be and I’ll find you.

— Drew Brees

Even If It Kills Me

I’ve got a lotta things to do tonight
I’m so sick of making lists
Of things I’ll never finish
I’ve lived here for the last 12 years
Since early 1995 all my shit has been in boxes
But if I had a little more time to kill
I’d settle every little stupid thing
Yeah you’d think that I would

But I’m too tired to go to sleep tonight
And I’m too weak to follow dreams tonight
For the first time in a long time I can say
That I want to try to get better and
Overcome each moment
In my own way

I wonder if I’ll ever lose my mind
I tried hard for awhile
But then I kind of gave up
Winter is killer when the sun goes down
I’m really not as stubborn as I seem
Said the knuckle to the concrete

But I’m too tired to go to sleep tonight
And I’m too weak to follow dreams tonight
For the first time in a long time I can say
That I want to try to get better and
Overcome each moment
In my own way

I’m not saying that I’m giving up
I’m just trying not to think
As much as I used to
Cause never is a lonely little messed up word
Maybe I’ll get it right some day
For the first time in a long time I can say
That I want to try
I feel helpless for the most part
But I’m learning to open my eyes
And the sad truth of the matter is
I’ll never get over it
But I’m gonna try
To get better and overcome each moment
In my own way

I sure want to get back on track
And I’ll do whatever it takes
Even if it kills me

— Motion City Soundtrack

Benjamin Franklin Quote: 11/20/09

Those who would give up essential Liberty, to purchase a little temporary Safety, deserve neither Liberty nor Safety.

— Benjamin Franklin

Carl Sagan Quote: 11/20/09

Where we have strong emotions, we’re liable to fool ourselves.

— Carl Sagan

Domain Parking

Nov 16, 2009

News

1 Comment

I own about 20 domains and until fairly recently some of those have been serving the default registrar parking page. See, I have this problem of impulsively buying domains. Brandy thinks it’s an addiction, but I have good intentions for all of them—there’s just not enough hours in the day. Some of them may or may not be projects that are currently in the works, but it’ll be some time before any are launched. However, I spent a few minutes today putting up some ‘parking pages’ for them. I doubt any of them generate a significant amount of traffic, but I thought it’d be nice to at least have them display my name. Plus, they all serve from the same place so I can easily make changes across the board.

Here’s the list:

  1. ampersanity.com
  2. btmcart.com
  3. imlookingforthis.com
  4. liciousthat.com
  5. robotfantasyisland.com
  6. tinyschedule.com
  7. twoschedule.com
  8. venturecouch.com
  9. yelching.com

In other news, I have two more single-serving domains that I’ll be announcing this week. They’re along the lines of Am I Addicted to Twitter, Loganlicio.us and Learn Your Damn Homophones.