I forked a Rails plugin for sending push notifications with Rails awhile back for a client project. I've had a few people fork and add cool little fixes.
I've been wanting to play with GemCutter for awhile now. How hard could it be to release a Rails plugin as a gem, right? I sat down and rewatched a Railscast on how to build a gems with Jeweler and push it to GemCutter. It turns out, that was the easy part. GemCutter and Jeweler made it so easy to publish my plugin as gem.
So I know this is very backwards, but after it was on GemCutter I tested it my new gem. (Yes, many smacks on the hand for not writing test. I'm still learning all of that.) It turns out, that it was completely broken. I started to try and fix things, but ended up doing a complete rewrite.
Before, it would add the model in the plugin to your search path and then you would have to run a custom rake task in the plugin to add the table and migrate the database for the model. This always felt a little dirty, so I abstracted it all out. Now you can do:
class Device < ActiveRecord::Base
acts_as_pushable
end
Pretty cool, right? Now sending is as easy as
d.send_notification :alert => "Hello world!"
(d being an instance of Device of course). You can read the full readme on GitHub. (Yes, another smack on the hand for no RDoc.)
Anyway, my code is probably very bad, as I'm pretty new to Ruby and Rails. I was very proud of myself for figuring it out. Check out the gem and let me know if you find it useful or stupid.
I've found myself setting up lots of servers over at RackSpace Cloud lately. It seemed look a good idea to automate everything instead of leaving it up to myself to remember everything you have to do each time.
I wrote this little shell script to make life easier. It installs everything I need to run a Ruby on Rails app in a matter of minutes. It's designed to work with Cent OS 5.4+. Here's the script's main tasks:
- Install Git 1.7.1.1
- Install Ruby 1.8.7p299
- Install RubyGems 1.3.7
- Install Passenger 2.2.15
- Install Nginx 0.8.45 (with Passenger and SSL modules)
- Install Postgres 8.4.4
- Initialize Postgres
- Install ImageMagick 6.6.3-0
- Install Bundler (latest)
- Open port 80 in iptables
- Open port 443 in iptables
- Start Nginx
- Start Postgres
For me, that's enough to get the bare bones of an app running. The rest, I let Bundler handle for me. I use this on all of my servers that I manage.
Let's get started already
All you have to do to setup your new server is run the following one line:
$ wget http://gist.github.com/raw/314865/new_server.sh;chmod +x new_server.sh;./new_server.sh
You'll have to press y twice at the beginning when yum asks you to install some stuff. After that, you can let it do its thing.
Configuration
It's super easy to add a new Nginx virtual host. All you have to do is add a file with the .conf extension to /usr/local/nginx/conf/virtual_hosts/. Here's a good example virtual host. Of course, you can configure any of the installed stuff like you normally would. My nginx.conf just makes setting up virtual hosts easy. After you edit any of the Nginx configuration files, you'll want to run service nginx reload to apply your changes.
One more thing
There's also another little script that I run after the main one that is more specific to my needs. This little guy creates /var/www/, setups the proper permissions, and installs some database related gems. You can run it with the following one line:
$ wget http://gist.github.com/raw/314865/z_after.sh;chmod +x z_after.sh;./z_after.sh
Updated 07/13/10: Bumped versions of packages and fixed ImageMagick