Archive for the ‘web development’ tag
Setting up Ruby on Rails in OS X
I consulted quite a few sources online to try and figure out how to do this, and ran into a few problems that took entirely too much time to solve. Now that I’ve figured them out, I’m writing the solutions here in the event I need them again. Hopefully they’ll be useful to a few other people as well.
Goals
Create a Ruby on Rails development environment with Apache, MySQL, and PHP.
There are several possible ways of doing this, but since OS X is a Unix-based platform, I don’t see any reason to use pre-compiled packages like MacPorts and replacing the built-in software. Plus, this is supposed to be a learning experience.
Sources
http://maestric.com/doc/mac/apache_php_mysql_snow_leopard
http://michaelgracie.com/2009/09/23/plugging-mcrypt-into-php-on-mac-os-x-snow-leopard-10.6.1/
Database Optimization: Indexing
After installing devise, I was looking through the migration file, and noticed a couple add_index commands. Reading up on what this actually does, I came across a couple interesting articles about database optimization:
Optimizing your MySQL Application
details: http://www.railsbrain.com/api/rails-2.0.2/doc/index.html?a=M001468&name=add_index
I don’t plan to build a giant Rails application, but Rails is known to have scalability issues. Still good to be aware of these points.
Ruby on Rails: on shared hosting, user authentication
* As usual, this post on Ruby on Rails is more documentation of my development process to supplement my notebook and memory. I can try to answer questions, but please keep in mind that I’m learning too.
I’ve bought the eBook version of the 4th edition of the Pragmatic Programmers’ Agile Web Development with Rails. It’s still in beta, but my main goal is to see how things have changed between Rails 2.x and Rails 3. The book also covers some basic user authentication, but it’s very simplistic. In the interest of getting my project up and going quickly, I looked into authlogic and devise/warden.
Both authlogic and devise/warden were highly recommended by mischa after building an application that did some direct comparisons of several different RoR user authentication solutions. Good enough for me. devise appears to be more lightweight, so I’ll try that one first.
A little bit about my server setup: I’m hosted with Lithium Hosting, which is a great deal and has fantastic customer service. They’re not paying me to pitch the service, though clicking the link above and then signing up for a plan gives me referral credits or something. It’s a shared hosting service, so I manage my site with cPanel if I need/want to, and I’ve added on SSH access to my account so I don’t really need to use cPanel.
Once the server upgraded to Rails 3.0/Ruby 1.8.7, a couple things happened: my rails apps stopped starting automatically (cPanel feature), cPanel could no longer start my rails apps, and I couldn’t create a new Rails app with a MySQL database.
Solutions:
1) install the mysql2 gem, which is the new mysql database adapter used by Rails 3. The compilers are disabled on my host, so this was done via support ticket.
2) add mongrel to my Gemfile,
#project/Gemfile
gem 'mongrel'
Mongrel isn’t automatically started in development mode. cPanel still won’t start my application, so starting the server is done via SSH with
rails server --port=[port]
So now I can create a new project
rails new project --database=mysql
and start the server. However, I don’t have a good way of authenticating users.
So, back to the support tickets to have both authlogic and devise installed. Once tech support has done that (seven minutes. really.), check if they’re installed for me:
gem server --port=[port]
and navigate to mysite.com:[port]. They’re not, run a couple commands from the command line:
gem install devise
gem install authlogic
Which should install the gems and make them available to me. Checking again as above, and both devise and authlogic are present. Add the appropriate lines to my Gemfile. Then, since I’m trying out devise first, install it:
rails generate devise:install
That’s all for now.
Ruby on Rails: Migrating data, too
Sometimes it makes sense to re-organize information in such a way that changing the database structure is necessary. It’s not terribly difficult to do this in Ruby on Rails.
I’m writing this more to file this away somewhere I won’t accidentally delete it:
Read the rest of this entry »
web design, and differences in browser rendering
Admittedly, it has been a while since I last really truly developed a website.
The FaCU site wasn’t so much of a site as it was a page, and really, I feel I could have done a better job if I weren’t so ridiculously busy Senior year, and if I were more up to speed on using CSS to lay out websites.
Every time I’ve done this, beginning seven years ago, I’ve hit this block around how to manage the layout of a site. The old way, working with browsers that didn’t correctly render CSS styling code, a lot of people dealt with the problem by using <table> hacks, using these tags to generate a website layout composed of “invisible boxes”. All fine and good, except that it made changing even the smallest design element on the site was a huge undertaking, because every box was made to align and fit together like intricate pieces of a puzzle, and adjusting the thickness of one border or the geometry of one cell within the table, even by one pixel, required tweaking of every element around it, sometimes even going back and re-generating images or other graphics.
My first effort at using CSS to lay out a website was in high school, when it became my project to design and build a website for the high school newspaper. I used it to learn not only PHP and how to interact with a MySQL database, but really everything that would be involved in developing a website. It never became as full-featured as I wanted it to be, and it was eventually wiped out in favor of something less complex, and then again more recently for a WordPress-backed system.
Long story short, I tried to learn CSS in high school, found it supported by the various browsers available at the time in a very inconsistent manner (between browsers), and ditched it because it was too confusing to figure out how do exactly what I wanted with it.
I came back to CSS during my Senior year at Columbia while I was working on not only the FaCU website, but also the website for my Senior Design Project. I tried to adhere to only the most widely available fonts, and the lowest common resolution for both sites. The result: fairly ugly sites, but they get the job done.
Fast forward to today, when I’m now working on moving all of the lab’s most commonly used inventory books into a user-friendly digital form. CSS has better support across every browser, and everything just makes more sense now. No idea why.
Still, CSS is still rendered with quite a few annoying quirks. Take, for instance, the following page layout:

Lab inventory site
Renders just fine in Chrome, Firefox, and IE8. The left navigation panel and the main content to the left are spaced and positioned properly. In IE7, the main content title renders where it should, but the table appears at the bottom, under the navigation block. In Opera, the positioning offset I used to place the content area to the right of the navigation pane doesn’t appear to be necessary, so there’s a giant gap where there shouln’t be one.
A better situation than I was working with seven years ago, but still irritating.
New (revived?) blog!
I’ve finally decided to revive my blog, though I’ve moved it from Blogger to my own domain and host so that I can make the most out of hosting I’m actually paying for and planning to use primarily to develop websites and applications I think would improve life or some process with which I’m intimately familiar.
So far, I’ve been spending my time trying to figure out how doing all of this on a shared host will change in comparison to all the online tutorials on web development which assume that work is being done on a local machine, and with complete root user access. I’ve done this before, but with each new host and new version of cPanel or other management software, the details change, sometimes dramatically.
Hopefully things will work out — let’s see what happens.


