rails


I want to do a little rant about web2.0 and then on some new things, like Google getting beat to the punch at one of the greatest new things to come out of this 2.0 gooball (it isn’t a bubble, just the graphics look that way)

Lets be clear about something, “Web2.0 is just web1.0 with prettier javascript” it is not a new web, it is not really anything new, it is fueled by ONE library and that libarary is named prototype and it is the glue that has allowed this thing we call “web2.0″ to come to where we are currently.

Prototype allows us to *not* have to hack around in nasty javascripts that are smeared throughout our html, it allows us to have access to the DOM in unprecedented ways and from the prototype wellspring has come all the libraries like script.aculo.us and moo.fx and dojo and.. and.. From these libraries have come plugins for frameworks like ruby on rails, django and cake which have taken prototype and made it easily accessible to your application. What the combined effect of these frameworks doing this is, is that now you really don’t need to know javascript inside and out to make use of the full power of it.

So, right now all you need is to look around you and see what people do online and with computers and even in real life and just like the mousetrap analogy you figure out a way to make it “better”, “easier” ot even just “fun”. You can get a cheap account at a webhost (however, due to many recent experiences and from listening to people you do NOT want to use dreamhost, I am without email for days at a time with one site I work with) then because “cheap webhosts” have a tendency to limit your bandwidth and your drivespace you can’t really run a very busy site on one. Now comes into play some new stuff which has recently emerged.

Amazon s3 (simple storage service) which I will make a bold prediction about.. “Google will be coming out with a storage system similar to s3 within a year of right now” and I would be willing to bet money on it. Yahoo will also more than likely try it as well.

Anyway, S3 is pretty amazing, it is quick easy and cheap cheap cheap. You host your larger files, user content, images, basically anything and it is almost a drop-in replacement for hosting your own files. It is metered so scales “with you”. If you are currently having to run one of those “platinum” plans from a webhost, you can drop down to their “basic” plan and host your images and files with S3 and save yourself a few hundred dollars per year.

The main reason I mention S3 is that after looking over the service and some of the implementations and playing around with my account I am impressed that it works so well and basically allows anyone with a few bucks to start a site that can be basically be scale-paid. Enough to the point that I can make another prediction, scaled webhosting which is based only on your gigabyte disk and line usage is most likely already out there, but will become the new defacto system and guys like cpanel, plesk and the large hosting providers like serverbeach will be quick to step up and get on board with this.

I am sure the apparently very smart people at Amazon saw this and so they said. Well, lets sell servers using the same model. And so was born Amazon EC2 (elastic compute cloud) need a new box? just fire up an image you have already uploaded (or use one provided) and there it is for ten cents per instance hour, or $2.50 per day per server or $75 per month before the standard costs for the S3 gigabytes/bw (totals come to about half of what I pay for my dedicated box)

So now we have metered unlimited space, any file can be turned into a torrent by simply adding “?torrent” after the file name (to save you some $), metered bandwidth and even metered instance time on a machine, it is all “pay as you go” and is built and designed for the smaller shops or even the medium sized businesses which could use a little work. To give you an idea of the savings, I worked for a mid-town company here in New York that paid thousands of dollars per month in bandwidth overages which would have amounted to perhaps $50 combined on S3.

To top all this off, Amazon now has a “People task” quick job board you can do called Mechanical Turk where you can hire people to do the little things for you, or take on little jobs in your spare time.

Today Google launched Google apps for your domain which really does nothing for me because I am not interested in branding my own version of gmail, everyone already uses the real gmail. They are usually pretty good about getting stuff out, but this is the first time I have really seen them being beat in something that is normally their domain.
When did Amazon get “cool” and Google doing the boring stuff?

So, for your little web2.0 startup the above links should be plenty enough to turn it out on a dime and also use and get your hands on the good stuff.

Some references:

http://www.holovaty.com/blog/archive/2006/04/07/0927

http://blog.pairwise.net/2006/08/28/a-simple-amazon-php-s3-class/

http://overstimulate.com/articles/2006/08/24/amazon-does-it-again.html

http://blog.pairwise.net/2006/08/22/amazon-s3-the-holy-grail-of-bandwidth-problems/

Just a quicky:

Every developer I have sent the link to gotapi to has come back and told me that it is now their home page or one of the tabs that opens when they start firefox. It has become and indispensable tool for me and those I work with. On one fast page you have the docs and fast lookups for every web development language (with the notable exception of python). My gotapi I keep with the following “HTML, CSS, Javascript, Prototype, MySQL, PHP, Rails Ruby and Ruby stdlib.

If you are a developer, go there, all the JAVA api`s are listed, C and C++, XML, actionscript etc.. It is the one stop shop for documentation.

To the guys who wrote it .. “Thank you”

Secondly, Protolize the ultimate web2.0/ajax/rails/cool list of links that is always just what you need.

Some other notables:
programming cheatsheets sort of like the “key cards” they supply in video games, but for programming languages.. Handy to print out and staple to some vertical surface at eye-level

Learning ruby links a collection of links that other people have found that I thought were worthwhile.

CSS event selectors sort of like behavior, but a little easier to use.

nice protype-based image cropper script that I can think of many uses for. One being to crop an image so that a section can be used as an avatar/icon for a website.

Open web design and Open source web design both great resources for that fast template you might need to mock something up or just get a framework for a site setup.

Just a few links I wanted to organize.

there is no cpaddon module for rails, so you gotta get your hands dirty. This is the fast way I got it to run, I will makes notes where needed. This is current as of August 2006 with the latest “stable” cpanel WHM.

As the root user, install ruby, gems, rails, fcgi, mod_fastcgi and add a configuration line to http.conf and restart as follows ( condensed from: here):

$ cd /usr/local/src
$ wget ftp.ruby-lang.org/pub/ruby/ruby-1.8.4.tar.gz
$ tar -xvzf ruby-1.8.4.tar.gz
$ cd ruby-1.8.4
$ ./configure && make && make install

$ cd /usr/local/src
$ wget rubyforge.org/frs/download.php/5207/rubygems-0.8.11.tgz
$ tar -xvzf rubygems-0.8.11.tgz
$ cd rubygems-0.8.11
$ ruby setup.rb

$ gem install rails

$ cd /usr/local/src
$ wget fastcgi.com/dist/fcgi-2.4.0.tar.gz
$ tar -xvzf fcgi-2.4.0.tar.gz
$ cd fcgi-2.4.0
$ ./configure && make && make install

$ cd /usr/local/src
$ wget fastcgi.com/dist/mod_fastcgi-2.4.2.tar.gz
$ tar -xvzf mod_fastcgi-2.4.2.tar.gz
$ cd mod_fastcgi-2.4.2
$ /usr/local/apache/bin/apxs -o mod_fastcgi.so -c *.c
$ /usr/local/apache/bin/apxs -i -a -n fastcgi mod_fastcgi.so

$ gem install fcgi

$ mkdir -p /tmp/fcgi_ipc
$ chown nobody.nobody /tmp/fcgi_ipc -R
$ chmod 755 /tmp/fcgi_ipc -R

Then in /etc/httpd/conf/httpd.conf add

LoadModule fastcgi_module libexec/mod_fastcgi.so
<IfModule mod_fastcgi.c> 
FastCgiIpcDir /tmp/fcgi_ipc/
AddHandler fastcgi-script .fcgi
< /IfModule>

install any other gems you want like rmagick and gettext and then restart apache however you like.. Remember if you install a gem you must restart apache to be able to use it.

Now to actually get rails running, follow what I have done with this domain use your own user

$ su people
$ cd ~
$ rails test
$ cd public_html
$ ln -s ../test/public/ rails
$ cd ../test/
$ chmod -R 777 tmp/
$ cd public
$ chmod 755 dispatch.fcgi
$ vim .htaccess

chmod -R a+rwx tmp is probably better than 777, but it is an afterthought to just getting this done

Change “dispatch.cgi” to “dispatch.fcgi”

Load up http://peoplesdns.com/rails/

One of the main issues I have seen from people is that they get it running but if the tmp directory is not writable then rails pukes and gives a bunch of errors, this seems to fix the issue.

An easy way to make rails standards would be to wrap /usr/bin/rails in a shell script by renaming rails to “runrails” and then having the rails script handle this, along with setting a “_RAILS” dir in the users folder and creating all projects inside that.

if you want to use mysql (duh)
gem install mysql

if you don`t do the above, rails doesn`t panic it starts spitting out “Lost connection to MySQL server during query” errors all over which really tells you nothing.. so make sure and install the mysql gem and save yourself some headaches.

install whatever other gems you want
Then if you actually want to use your gems, you must
/etc/init.d/httpd restart
it is sort of like installing anything on windows, you gotta reboot the whole thing.

Anyway, though that might come in handy for someone.

I have been working professionally as a PHP programmer for a long while, I recently began working for a new company and we are working all in rails.. I will be doing some recording of my progress.

Having worked previously in ASP (many moons ago) and then working in PHP for six years I first have to say that rails is “different”.
I have basically avoided frameworks as the ones in php try to turn php into something else that it is not. My general development was speedy though maintenance was not always the best on “fast” sites. For me, I have a base library of functions that I have found or written that I know I use and in general use to build up an application quickly.. I think part of my general avoidance of frameworks was that I didn`t want to use a different templating system, I have an extremely flexible one I made (and since have seen horrid templating systems in other corps, I think most people don`t understand the basics of templating at all. If you are going to create a templating system don`t even give the templates themselves the php extension, use .tpl or .tplt or whatever just to keep you from being seduced into that and running loops in them instead of reusing fragments.
Anyway, Rails provides a templating system, it provides a nice set of classes and it starts you off with excellent organization and does a lot of the work for you.
I have actually found it is easy to switch to rails for the simple fact that it is NOT using php, because I would be too tempted to start just changing things and hacking it up. I really am more of a backend programmer than anything, I prefer JSON+JS for frontend work.

There are many many things I really like in rails so far, the AJAX support is astounding, in a few lines I can do what used to be a full days work. I am in love with database migrations, and the database model system, in one fell swoop it fixes 75% of the issues you run into with php apps and data validation.

It is not all roses though:
One of the main gripes I have is that the rails docs does not have a comment system like php.net … this is a total travesty and it needs to be done, most people get more from the comments than from the documentation. I myself have contributed several hundred comments to the PHP site over the years (which comprises of the majority of all the php-ncurses docs + undocumented php-ncurses functions) comgin from PHP this totally BLOWS not being able to have this kind of resource. Sure, fxri is a nice way to find stuff, but it would really be handy to not have to search all over to find rails docs with a little programmer commentary.

Rails has some tight control over globals and it is never easy for a programmer to know the “scope” of a variable or a function. Take “request” for instance, I had to dig around for a while to finally figure out this is where the rails equivalent of the PHP $GLOBALS was, and then I found out that it was not actually “global” because I could not call it within functions in a helper. Also it was not entirely clear what the @ and : variable signifiers were from the start, this was frustrating until I sort of figured it out.

The only other issue is not really rails specific, but due to the fact that working with rails you need to have so many files open that trying to use my editor “gvim” is difficult at best, even with buffers keeping on window for each directory I end up with thirty gvims open and have to hunt for things so I switched to jedit which kind of bothers me a bit becuase over the years I have collected some useful vim scripts that I love.. one is a code columnizer (nice groupings of code all line up) and others are for comments and timestamping as well as in-file only completion (which is handy when you are working with strange files to have completion for some of the strange stuff)

Not a lot of gripes really, rails is nice and I will be writing a lot more about here saying that I am diving really deep into it and soon will be working on server-side issues a lot.

I will try to keep this up to date a bit more.