10 posts tagged “ruby on rails”
The Rails apps I've written are deployed on a shared host, which is fantastic because the sysadmins can come around at any moment and pull the rug out from under me by changing something in the configuration. Yesterday, I logged into one of my apps only to be greeted by a wrong number of arguments error. Not cool.
After a bit of Googling and investigation, I noticed that Rails had recently been updated to version 1.2.3 for compatibility with the newly released 1.8.6 version of Ruby. My hosting provider had updated Ruby, but not Rails. Also not cool...as far as I can tell this will break any Rails app that uses a MySQL database, which would be almost all of them.
Luckily, there's an easy way to get your Rails app back in business...just freeze a copy of the correct version of Rails into your app. (Basically, this will copy all of the Rails code into the vendor/rails directory of your app.) In my case I "upgraded" to Rails 1.2.3, because that's the version that works with the Ruby install on my host. You could also "downgrade" and keep an older version for backward compatibility.
All in all, this was pretty easy to fix once I figured out what to do, and it was a good learning experience. However, I will still be notifying my web host of this issue, because I think they should not be so quick to update the software without considering the consequences.
Computers are such a pain in the ass sometimes.
I am not a fan of spreadsheets, and finding myself encountering them more and more now that I work for a larger company. This distresses me, so let me reiterate: Please don’t use a spreadsheet if you’re not calculating numbers. Even then, you might not need one. (Word can easily add up a column of numbers, for example.)
We live in a wonderful world containing many other compelling options to meet your data storage needs. One I’m examining carefully as of late is called Dabble, and it’s kind of like a web-based version of Microsoft Access or FileMaker, but much easier to use.
Dabble helps folks kick the Excel habit by easily importing data currently in spreadsheet form, and then giving the user the ability to work with it in ways that spreadsheets simply can’t. For example, you can create a dropdown list of options for one of your column values or display date data on a calendar (very cool). This is harder to explain than it is to see, so if this sounds interesting to you please watch this short video that shows Dabble in action. If you find yourself outgrowing your spreadsheets, it just might be for you.
As cool as it is, Dabble could use some improvement in the reporting department. There are a number of nice export options, and a pretty good PDF output feature, but there’s no proper report writer in the current version. (If I were them, I’d consider making the basic functionality free and charging for this.) This is the main thing I’d be giving up if I moved some of my custom Rails apps to this platform.
Speaking of Rails, it’s so easy to create a Rails app that in many cases doing so to replace a spreadsheet is a compelling option. I whipped together an invoicing app for my wife’s speech therapy business in about a week working only in my spare time, and if I’d known about tools like Streamlined, it would’ve been even easier. (Of course, I was still in my previous job at the time, which was much less demanding.) Obviously, you’ll need some programming skills to do this, but not as much as you might think. If you’ve ever thought about programming, there’s never been a better time to jump in.
Hopefully, I’ve expanded your mind a bit and you’ll think twice before double-clicking on that old icon. And for all you geeks out there, I’m counting on you. After all, friends don’t let friends use Excel.
Debugging Rails apps usually involves shutting down and restarting your server. Locally, this is a piece of cake: Ctrl-C. On a shared host, it can be tricky to shut down your server.
After a little bit of digging around in forums, I found out you can do it this way:
# pkill -9 -u `whoami` -f dispatch.fcgi
This of course presumes you have access to the command line. You don’t have that? Switch hosts.
Oh, and restarting? Just hit your app’s URL. You want to be the first one to do this anyway, so that it gets all the initial loading stuff out of the way.
If you’re one of those people with an eye for details, you may have noticed that this blog looks a bit different than it used to. I’ve switched from the WordPress blogging engine over to Typo, the cool new kid on the block.
Why?
- Comment spam
I don’t like comment spam. I had a lot of it. It was not good. Typo posts comments via AJAX, making it trickier to spam.
- Built-in tagging
I do like tags. For some things, anyway, and organizing blog posts is one of them. I had to use a plugin to get tags happening in WordPress.
- Nicer look
(In my not-so-humble opinion.)
- Ruby on Rails cool factor
RoR is just cool.
- Better, more flexible code base
Since Typo is just a Rails app, I can easily dig into the code if I want to see how something works or change something.
If you’re considering such a switch, keep an eye on the next few posts. I’ll be sharing what I learned and providing some tips that will hopefully save you time.
UPDATE: I have switched web hosts and can no longer host this Rails app in a running form. You can still download it and use it yourself.
--
I guess it is a small world after all. About two months ago I created a FeedFlare to make it easier to post your articles to digg. Wouldn’t you know it, I’m surfing the web a few days ago, minding my own business, and I see that not only is someone else actually using this FeedFlare, but posting the item to digg caused a huge traffic spike to his web site! As John ‘Hannibal’ Smith used to say, “I love it when a plan comes together.”
So, I was inspired to create another FeedFlare…number 56 on the list of 101 Flares: Feed Circulation. If you’re lucky enough to get your item on the digg home page, this is an easy way to watch your numbers go through the roof. ;)
This FeedFlare is dynamic (meaning there’s actual code that makes it work) and uses FeedBurner’s Awareness API. So, before you use it, you’ll need to enable Awareness API access to your feed.
How can I use this for myself?
It’s easy:
- Login to your FeedBurner account.
- Go to the
Optimizetab. - Click
FeedFlarein the left menu. - Copy/paste this URL (http://rossbelmont.com/feedcirculation.xml) into the text box under
Personal Flareand clickAdd New Flare. - Scroll down to the bottom and click
Save. (This is easy to forget.)
This doesn’t seem to work for me.
I tried to keep this pretty simple to avoid any problems, but, hey…stuff happens. To that end, I wrote this in such way that you can “debug” this a little with any web browser. If you’re having issues, hit this URL:
http://www.rossbelmont.com/feedcirculation/↵ circ?feedUrl=YOUR_FULL_FEED_URL_HERE
So, in my case, this looks like:
http://www.rossbelmont.com/feedcirculation/↵ circ?feedUrl=http://feeds.feedburner.com/Arbited
(Make sure to include the full URL.) You might see an error message like the following:
Error occured (1): Feed Not Found
The error code 1 and the message Feed Not Found are returned from FeedBurner and can be looked up on this page. They’re informative, if not exactly verbose, and they should help you pin down what went wrong.
If you see a tiny snippet of XML that tells you how many subscribers you have, you’re good to go.
How does this work?
Three words: Ruby on Rails. If you’d like to look at the code (or run it on your own server instead of mine) you can download it here.
It’s pretty straightforward, really…it grabs your feed URI from the full feedUrl and makes a call to the FeedBurner Awareness API to pull up the number of subscribers. That number is embedded in the XML the code returns, which is then parsed and displayed in your feed or on your site.
To give credit where credit is due, the code to parse the XML returned by FeedBurner was aped from the Ruby wrapper for the Backpack API, written by DHH himself.
I hope y’all like this…I’d love you get some feedback on this so please post a comment if you have any.
Let me set the stage a little bit: I was playing around with 30 Boxes and I had an idea for how to create Backpack reminders via e-mail or SMS. I threw that together without too much hassle and I was feeling pretty good about myself.
So, a little later on, I was looking at 30 Boxes more in depth, and as I was contemplating ditching iCal I was thinking that one thing I would miss is my Backpack reminders being embedded into my calendar. Backpack lets you “subscribe” to your reminders as another calendar using the iCalendar format.
Lo and behold, I was poking around in the 30 Boxes settings when I discovered that it has the ability to display RSS feeds in an embedded manner in your calendar. It was at this point when the wheels started turning. ;)
So, I whipped up another little Rails app to serve my Backpack reminders as an RSS feed. I’ll admit it’s somewhat underwhelming to simply read this feed in your aggregator. But, if you plug it in to 30 Boxes, it’s pretty sweet.
How can I use this for myself?
Unlike my previous Backpack API hack, this one basically requires that you have a web hosting account with a provider that supports Ruby on Rails. If you’re in the market for one, I’ve been really happy with my experience at A Small Orange. I’ve also heard good things about Textdrive.
The other thing to watch out for here is security. You don’t want anyone who can guess the URL to be able to read the feed. So, I embedded a randomly generated security token in the URL that is “unguessable” for all intents and purposes. Also, I avoid storing that token in the source code in clear text by using a standard encryption algorithm. Just keep in mind you’ll need to deal with this.
To use this, the steps are more or less as follows:
- Download the Rails app (reminderfeed.zip, 64 KB).
- Edit the file
app/controllers/feed_controller.rbto include your Backpack username and API key. - Choose a security token to be embedded in your feed’s URL. In this example, let’s pretend it’s
mytoken. - Generate the SHA-1 hash of your security token using this Ruby script, and put this value in the appropriate spot on line 6 of
feed_controller.rb. - Upload the Rails app to your web host and test the URL. It should be something like
http://myhost.com/reminderfeed/feed?sectoken=mytoken.
That’s all there is to it.
How does this work?
The code here is so dead simple, it’s almost sample code. Go ahead and poke around in there if you’re interested in how it works…the files of interest are app/controllers/feed_controller.rb and app/views/feed/rss.rxml.
If you look at rss.rxml, you’ll notice that I ran into a time zone gotcha because my web host is in a different time zone then my Backpack. If anyone has suggestions on how to improve this, holla atchya boy.
So, what’s next?
Word on the street is that Backpack will grow a calendar of its own, and maybe I’ll be able to throw this code out the window. No biggie…it was still a good learning exercise and it took maybe an hour tops.
It’s no secret that I’m a huge fan of Backpack. And though it’s great to store all my miscellaneous info and personal mini-projects in one central location, I’d forget to do anything without Backpack’s reminders feature. It’s simple and it works beautifully.
The one problem I have with Backpack reminders is that I almost never think of the things I need to be reminded about when I’m sitting at a computer. And, unfortunately, the browser on my phone just takes too long to load, or else I’d use Backpack’s mobile version more often. However, the GUI on my RAZR isn’t so crappy that I can’t dash of a quick SMS before I forget my critical reminder-worthy thought.
So, what I’ve done is whipped together a quick Rails app that gives me the ability to create Backpack reminders via e-mail or SMS. Here’s how it works:
- Realize that you haven’t called Aunt Betty in a while.
- Whip out your phone and type
call aunt betty sat aftinto a new text message. - Send the message to “remindme@someaddress.com”. This can be any e-mail account you have that supports POP3.
- Sometime later, the software I wrote picks up the message and sets a Backpack reminder for Saturday at 2pm with the text
call aunt betty. - Go about your business until Saturday afternoon, when your Backpack reminder fires off, and alerts you either by e-mail or SMS.
- Call Aunt Betty and stop feeling guilty.
You can use any e-mail program to send a reminder message to the “remindme” address, which is handy when you’re in front of a computer. The SMS example above relies on the feature most cell phones have in which a text message sent to an e-mail address magically “becomes” an e-mail.
I got the idea for this after experimenting with 30 Boxes, a new online calendar app. They have a nifty little feature they call the One Box that allows you to add appointments to your calendar just by typing in something like dinner fri 6:30pm. It figures out when Friday at 6:30pm actually is and creates your appointment.
In my version of this, you can enter the date and time in either order. Here are some other examples:
Call Dave(reminds you in three hours)Pick up dry cleaning 5pm wed(time comes before date…that’s OK)Make doctor's appt tom(reminds you tomorrow at 9am)Pick up dinner 5pm(reminds you today at 5pm)Send in taxes 4/15 9:30am(You do pay your taxes, right?)Report for active duty 9/1/07 15:00(Sept 1st of next year at 3pm)Post files soon(reminds you in 10 minutes)
Those of you that use Backpack reminders already will recognize morning and afternoon corresponding to 9am and 2pm, respectively. I also added the keyword of night (or nite or even nit) to translate to 6:45pm. Call Dave later will work the same as Call Dave, reminding you in three hours. I also added soon to remind me in 10 minutes because you’d be surprised how quickly something flies out of my brain. Finally, you can enter the input text into the subject line of the e-mail or the first line of the body itself.
How can I use this for myself?
Unfortunately, I can’t host this application for you, so you’ll need to download and run it yourself. But, on the plus side, you don’t have to pay for your own web hosting account either. All you really need is a computer that can run Ruby, and a way to kick off the script to run every once in a while.
Here’s what you’ll need to do, in no particular order.
- Obtain a POP3 accessible e-mail address you’ll use for this purpose.
- Download the Rails app itself (mobilereminder.zip, 76 KB). Go here if you don’t have Ruby on Rails already.
- Edit the file
lib/checker.rbto specify your e-mail configuration. - Edit the file
lib/reminder.rbto specify your Backpack account info. - Run the Checker every so often. I used
cronto execute the following command every five minutes:
/usr/local/bin/ruby mobilereminder/script/runner ‘Checker.run’
If you actually want to set this up but are having trouble, drop me a line and I’ll try to give you a hand.
How does this work?
Essentially, I set up a cron job that kicks off the process every five minutes and POPs off all the messages. It parses each one, sets a reminder if there’s a future date, and deletes the messages. It’s pretty solid, overall…I only got one error from the cron daemon about an issue accessing the POP mailbox that didn’t resurface.
The parsing was not that hard, really, because Ruby’s such a cool language and has so many great features baked right in. This definitely would have been a bigger pain to write in Java, severely reducing the fun factor. Also, I’ll note that this took me about a week of nights and weekends to put together, and I’m not a Ruby expert. Now that I think about it, that’s probably something worth repeating: I’m not a Ruby expert or a master, wizard-level coder. If you download the code and laugh at it, that’s OK. At the same time, if you have a suggestion for improvement or want to help me out, by all means let’s chat.
Speaking of master coders, I need to give credit where credit is due and point out that this was possible to put together because the good people at 37signals have released a really nice API for Backpack. But, more than possible I’d say it was easy to put together because they went one step further and created a sweet Ruby wrapper that made the Backpack calls drop-dead simple. The only way they could have been better is to add this feature into the official Backpack product and render my silly hackery irrelevant. (Hint hint!)
There’s one gotcha to this whole thing: since there’s no way to determine which time zone your Backpack is in through the API, I had to hard code some stuff in there to offset for Central time because my web host is on Eastern time. If you run this app from within the same time zone as your Backpack, you can delete the offset stuff from the code.
So, what’s next?
Well, I mentioned at the beginning that I got the idea for this by using 30 Boxes…my next app gave me a way to display my Backpack reminders on my 30 Boxes calendar. Check it out if you’re interested.
I’ve just completed my third Ruby on Rails mini-project and it’s time for me to officially say it:
Ruby on Rails is cool.
I know, I know…you’ve never heard this before. I am the first person to ever blog this. But, rest assured, it is true.
It’s both easy and fun to whip up little web-oriented apps in Rails. Most of my experience is in Java, which is easy enough but not exactly fun. Ruby is a very neat little language with almost no “overhead.” It’s super-easy to get started and get some code running with a minimum of rigamarole.
I’m running my apps in a “beta” mode right now, and if I don’t see any bugs in the next couple of days I’ll post them soon enough. You might want to use them for yourself if you have a Backpack account and/or a 30 Boxes account.
I’m not above of a shameless plug every now and again, especially if it’s for something really good. Such is the case with Echo2, a GUI framework for Java-based web applications. If you’re doing web work in Java I highly recommend you take a look at it and see if it meets your needs.
Why am I bringing this up, you ask? Well, I just happened to be flipping through the recent issue of PC Magazine (dated December 27th) and the Internet Solutions section has an article titled Better Web-App Interfaces with AJAX. (It’s on page 76.) It discussed why AJAX is cool from a high level perspective and recommended that if you’re building a web application and you want use AJAX, it’s a good idea to use a framework that has support for it built-in. The examples of Echo2 and Ruby on Rails were cited.
Seeing Echo2 receive a plug in a major publication like PC Magazine brought a smile to my face because I used to work for/with the folks that developed Echo2. Some very, very smart dudes and I learned a lot from them. I wish NextApp all the best.
Interestingly, before there was a NextApp, the precursor to Echo was just something we used in house to develop web apps. About five people in the entire world new what it was. Later, Echo was released as an open source project and a community developed around it out of thin air.
That, to me, is the most fascinating part of the story: if you make something good enough, and simply put it out there, the world will take notice. It’s just gotta be really, really damn good.
It’s just that simple. ;)
