Forms in Ruby on Rails - Part 2
July 11th, 2007
In the previous installment, we learned about two of Rails’ methods that help create forms, form_for and remote_form_for. Those methods dealt with forms primarily based on Model data. Today we’ll turn our attention to form_tag and form_remote_tag which create more generic forms not tied to Model data.
Tutorial after the jump…
Read the rest of this entryForms in Ruby on Rails - Part 1
July 8th, 2007
I was confused for a pretty long time about how to create forms in Ruby on Rails. Since many (most?) Rails applications are tied to databases, it makes sense that many interactions with model data will be done via HTML forms. My problem though, was that there just seemed to be too many choices, and the choices are poorly named.
Tutorial after the jump…
Read the rest of this entryRubyNoob Reborn!
June 28th, 2007
After months and months of neglect, primarily due to the fact that I’ve had tons of problems getting Typo to run properly on Dreamhost, I have finally revived RubyNoob running in Mephisto! RubyNoob is up and running on a slice from SliceHost, being served by Litespeed.
I’m planning on writing up some guides on how I did the transition from Typo and Dreamhost to Mephisto and Slicehost, but first I’d like to thank Paul over at UsefulJaja for creating the incredible tutorials that I followed in setting up my new slice.
As I’m writing this, the new RubyNoob is using the plain generic Mephisto theme. I’m planning on slowly evolving my own theme over the next few months. I’m hardly a web designer or expert in CSS, but it’s time that I learn and what I’d like to do isn’t really anything spectacular or complicated.
Since my last useful posts I’ve learned a lot of stuff about Ruby on Rails. I’ve added a full e-commerce solution to JoyLi.net by integrating it with Google Checkout. That was a great experience and I’ll be writing about that as well.
If you’re reading this, you’ve found your way to the new RubyNoob (or your RSS subscription actually figured out what happened and I’m amazed) and I’d like to thank you for stopping by. Let’s hope I keep the ball rolling from here on out!
Note: all comments since the migration have been given the date of the migration, sometime in June 2007. Please ignore all the comment dates.
Rails + Errors + FastGI == Bad
January 24th, 2007
One way to generate a lot of “500 – Application Failed” errors in Ruby on Rails applications running on Dreamhost is by throwing a lot of errors. Right now my newly downloaded Typo (supposedly the most recent stable version) is throwing some errors and this is, in part, causing RubyNoob to keep going down.
I’m investigating this to see what I can figure out. My advice is, if you’re running Rails on Dreamhost and you keep getting application failure errors, the first place to look is your production.log file. Make sure to clear up all errors first.
I’ll talk about what else you can do once I get RubyNoob a bit more stable.
Windows is Evil
January 24th, 2007
Simple lesson for other Ruby on Rails noobs – editting dispatch.fcgi in Windows and then uploading to your website may be hazardous for your site!!
Although I haven’t had other issues with doing so, after totally destroying RubyNoob over the past few days, I’m always going to do any editting of dispatch.fcgi through my Dreamhost shell! Apparently some invisible characters can get into your file and keep your site from starting up.
I’ve also updated to the latest and greatest typo, but in the process I’ve lost the comments for the 4 or 5 most recent posts – and that sucks. I’ll see what I can do to resurrect them – or at least the ones worth bringing back.
I have an interesting article coming soon about Dreamhost and Ruby on Rails and Applications failing to start. I’m going to try to make the changes I’ll be mentioning and we’ll see if RubyNoob becomes more stable.
Introducing JoyLi.Net
January 23rd, 2007
In conjunction with my wife Lindsay, and our development company, Blue Cockatoo Creative (website in progress), we’re proud to annouce the release of our first, full-fledged Ruby On Rails website, JoyLi.net.
Lindsay created the graphics and the general web design, while I stitched the pages together, created the database and did general rails magic. There’s no real Ajax on the site, though we did include a bit of groovy javascript.
Lindsay talked me into using ThickBox and JQuery instead of the standard Prototype and Scriptaculous libraries which have built-in support in Rails. Her argument was that we’d save time by not forcing users to download those other libraries and I relented, though after we finished I think we both agreed to just use what ships with Rails in the future. If someone goes ahead and fully integrates JQuery into rails, though, we’d stick with it.
Here’s a couple of teaser images:


JoyLi.net took us about 90 hours worth of total effort. It uses mysql and is currently running on FastCGI on Dreamhost. So far we don’t seem to be experiencing the horrible 500 errors that many people get with Dreamhost. I think I may have found a solution to those problems, and I’ll blog about that soon.
For fun, watch the home page for more than 15 seconds or so. Javascript is fun!
Please leave a comment and let me know what you think!
How To Deploy your first rails app to Dreamhost using Capistrano in Windows
September 21st, 2006
Credit: This tutorial owes its existence to the wonderful Dreamhost/Capistrano wiki article.
The primary thrust of this tutorial will be to help you deploy your first rails app using Capistrano from a Windows environment. Although I’m specifically addressing deploying to Dreamhost, you may be able to modify things to work with your own host. Rails apps on Dreamhost usually run on Fast-CGI, so this tutorial covers that as well. You may need to find more information in order to get your app up and running on Lighttpd or Mongrel.
Read the rest of this entryHow to download files with a Ruby script
August 21st, 2006
I figured that it would be an awfully easy task to download pictures from the internet using Ruby, and it is, but it was very difficult to find good examples. I googled for an hour or so, and kept coming up empty-handed. Finally, I checked in gmail where I keep mail from the Ruby Language mailing list. I found a relatively straightfoward way to do this.
Let's say that you want to download a picture from flickr, and you know its URL. Here's the ruby script to download the file:
1 2 3 4 5 6 7 8 9 10 |
require 'net/http' Net::HTTP.start("static.flickr.com") { |http| resp = http.get("/92/218926700_ecedc5fef7_o.jpg") open("fun.jpg", "wb") { |file| file.write(resp.body) } } puts "Yay!!" |
The Net::HTTP class contains the magic needed to handle this operation. I don't think this will work at all if you need to pull down a file from an FTP server. For now, we're dealing with http urls. So, just strip off the "http://" portion of the url and everything after that up to the first / goes into the start method.
Now, we get the file. The rest of your image url after what you put in the start method goes into the get method. This grabs the file from flickr.
Now we're going to copy the file down to where the script is running. First, let's create the file we're going to copy the picture into. Using the open method, the first parameter is the name of the file that you're going to plop the picture into. We could have used "218926700_ecedc5fef7_o.jpg" or anything else here. The second parameter of the open method, "wb" indicates that we're opening the file for (w)riting and we're going to be writing (b)inary information. The "b" may not be necessary on non-Windows platforms.
Finally, we're going to write into the new file, the contents or "body" of what we grabbed from flickr. So, this writes in the binary bits of the picture into fun.jpg. Remember that with the way that we created fun.jpg it'll be in the same directory with our ruby script.
This same method will copy down .html files, .css files, .pdf's and just about any other kind of file. In my next RubyNoob entry, I'll write about how to combine this method with a flickr api call to grab an arbitrary number of recent photos from flickr. As usual, I'm still a noob, and there's probably much better ways to do this. If you know a better way, please share in the comment section below.
I currently do my development work on a WindowsXP PC running Subversion through Tortoise and I’m currently hosting sites with Dreamhost, a popular site for Ruby on Rails and PHP hosting. This is going to be a tutorial on how to get your rails apps up in a repository on Dreamhost, but you’ll be able to use to coordinate any sort of subversion repository on dreamhost.
The 20 Coolest Ruby Apps You've Never Heard Of
July 13th, 2006
Actually, I have heard of a few of these. BillMonk is a pretty darned cool idea for the younger, poor college aged crowd. CommunityWalk is another of my favorites, but I didn't realize it was written in Rails.
Blogged with Flock
More fantastic resources
July 9th, 2006
Excellent RJS Reference List
July 5th, 2006
Lightbox Version 2
June 1st, 2006
Still here!
May 30th, 2006
How to Send Files in Rails
May 19th, 2006
First, put the file out on your server. I put my "README.txt" file in a "files" folder like this: "rails/ appname/files/README.txt."
Next, set up a link in one of your pages:
1 2 |
<%= link_to 'Get Readme', :action => 'get_readme' %> |
1 2 3 4 |
def get_readme send_file("files/README.txt", :filename => 'yo_readme.txt') end |
There are other options like the :filename option which allow you to tell the browser what type of file to expect, how to display the file, and whether or not to stream the download. Streaming is turned on by default and allows downloading of very large files. All of these options go into the same line of code. Take a look at the article at this link.
As usual, expect a quick video demonstration of this posted later tonight.