Rails
June 18th, 2008
So it’s been a while since I last updated, though it’s hasn’t been a few months like it’s been before. Anyway I started playing around with Rails again this past weekend and it is the most amazing programming language I have ever used. I’m building out the new thefridaycontest.com in it and in 10 lines of code and only 15 minutes I had voting taken care of, including setting a limit on requests by IP address. I’m working on a new site for my cousins business in it as well.
What I like most about Rails is the database interaction. The steps to setup a database table for content [on my MacBook] are:
- Generate a model with Terminal.app (script/generate model content title:string body:text)
- Migrate the database in Terminal. (rake db:migrate)
Fill the table with some content and then from the controller in your page definition (index, new, edit, show, etc.) you simply write:
@content = Content.find_by_id(params[:id])
That basically tells the controller to use the Content model and then find the record by it’s id (which in most cases is the third part of the url after the .com/, so in content/show/1, 1 is the id). After that in the view it’s just simply a matter of calling <%= @content.fieldname -%> to write the data to the screen. If I had to do this in PHP it would take at least twice as long since I’d have to create a database in phpMyAdmin, then write a connection script, then query the database, and finally return it as an associative array for easy use in the page.
I’m still learning, but just from experience this has been the easiest language to learn thus far. In the last few months I’ve had to learn a bit of C#/ASP.Net for work which completely sucked and was a royal fucking pain to learn. PHP took me a awhile to learn initially too, but then again PHP and Rails I learned/am learning on my own time, and not because I had/have too.
the friday contest
May 9th, 2008
At my office we’re doing a “Theme Friday” contest. Where the previous week’s winner picks the theme for next week. So since everyone in the office would vote for themselves, I’ve created a way for the everyone in the world (in theory) to vote. Introducing thefridaycontest.com. Every week there will be a different contest. This starts next week with my theme (which I need to pick today) but the site is live now. iPhone interface will come eventually.
I have to create a mini-admin for uploading new photos and updating theme information, but other than that it’s done. I’m deploying it using SpringLoops. It took over 40 versions and 7 hours to create. I like what I ended up with. So come on feedback, like it, hate it, etc.?
jQuery “click” and Safari
March 13th, 2008
Earlier this week I was working on migrating a online donation form that connects to Authorize.net for credit card and bank account donations into a Drupal installation. I built the original form and at the time had used Script.aculo.us to create sliding content blocks that appear when you switch between a one time contribution and an automated recurring contribution. Everything worked great in every browser I tested.
During the migration I ended up re-writing the script and decided to ditch Script.aculo.us for my Javascript library of choice, jQuery.
Everything worked great as before, a few bugs popped up because of they way it had to be setup. After fixing those bugs and sending it to the client for approval, I was informed (by the client) that the sliding panes don’t work in Safari 3 for the Mac. I opened the page in Safari and sure enough they didn’t work. After checking that the Javascript file had indeed loaded, I looked on Google just knowing someone had to of experienced this same problem.
I didn’t find anything, which was discouraging at first until I had an idea. I had used code similar to $(’.field’).focus(); with a function to run when you focus on a form field (usually radio buttons). I made a duplicate of my Javascript file and then did a find and replace. Replacing every occurrence of “focus()” with “click()”. Tested the file and sure enough the panes worked in Safari. I’m not sure why “focus()” wasn’t working, focus should be a valid event in every browser. If anyone has information on why “focus()” in jQuery doesn’t work on Safari 3 for the Mac, I’d be interested in hearing it.