GAPDesigns

Rails and PostgreSQL on Fedora 9

The recent Oracle-Sun acquisition on top of the mass exodus of MySQL developers from Sun has convienced my that my current project would benefit from a switch from MySQL to PostgreSQL. I was not to familiar with Postgres, so figuring out exactly how to install Postgres and migrate my Rails app to it was a little harder then it should have been. So, here is a quick and easy guide to Rails on Postgres and Fedora (9).

1) Install PostgreSQL

This is easy, just like MySQL (you may not need the development package...).


$su -
#yum install -y postgresql-server postgresql postgresql-devel

2) Configure PostgreSQL

Postgres is a bit different then MySQL at this point. Before you start the postgres service and set run levels you must assign the file space for the databases to use with the initdb command.


# service postgresql initdb
# service postgresql start
# chkconfig postgresql on

Now we need to create databases and users. The first thing we need to do is log in as the postgres user.


# su - postgres

As the postgres system user we need to create a db user. This first account will be a super user.


$ creatuser -D -A -P superdbuserdude

Then enter your password twice and hit y.

Now we can create databases...


$ createdb testdb

...and drop them.


$ dropdb testdb

However, we are still very limited on how we can access postgres. First log out of the postgres system user and back to root.


$ exit
# whoami
root

Now we need to edit the "host based access" config file to allow username/password logins on the local machine. (As opposed to only allowing a login if the system username is the same as the database user name - the default setting.)


# vi /var/lib/pgsql/data/pg_hba.conf

It would help to at least read this file a bit, but what we need to chang is down towards the bottom. Look for an uncommented line that reads:


local   all         all                               ident sameuser

Change it to: (press i to change to insert mode and then backspace and type)


local   all         all                               trust

Then save and exit. (press Esc then type :wq then press Enter)

Now postgres is all set up. We are just missing one step..

3) Install Ruby-Postgres Bindings

As root install the Ruby postgres Gem. Some people recommend the ruby-postgres gem instead of the postgres gem so maybe you should use that, but at the time of this writing the postgres gem had been updated more recently and is what I used.


# gem install postgres-ruby
--OR--
# gem install postgres

4) Profit??

You can now create more users and databases as we did in step 2 and create rails applications on postgres.


$ rails testing_pg --database=postgresql

You will have to set up a user and database for the app and edit the config/database.yml file to reflect your set up.

Enjoy PostgreSQL!

jQuery $(document).ready IE/Chrome Issue - Captilization Matters!

Just wanted to post this up really quickly because it caught me off guard. Capitalizing the D in document will work in Firefox in Linux and Safari on OSX, but not in Chrome on Windows(Vista) or IE6 or IE7.


$(document).ready(function(){
  //Good
});

$(Document).ready(function(){
  //Bad
});

No, I do not know why I ever capitalized it.

That is all... Hope this helps someone. :)

Using the jQuery history plugin with Rails

On a recent project I was doing a lot of Ajax page loads for a "dashboard" type page. It was a case where I felt an Ajax approach was required. It was an internal project, so requiring JavaScript was not a problem.

However, I did have one major issue with the system. The back button was broken. This was a huge usability issue and needed to be resolved.

Rendering layouts with Ajax in a RESTful controller

In today's modern day web apps, the polish Ajax can provide is essential. However, you need to ensure that your application degrades nicely for those who don't have, or are not using, JavaScript; including some mobile users.

When requesting html from a scaffold generated REST action in a Rails app with an application layout you end up with a layout inside of a layout. Not what you wanted.

However, Rails provides the request.xhr? method which returns true or false. This actually just checks to see if the X-Requested-With request header was set to XMLHttpRequest by Prototype/JQuery.

RSpec, Autotest and libnotify on Fedora

There is a lot of stuff out there for using libnotify with your RSpec and autotest and Ubuntu, but not much for Fedora. Here is how I did it.

Google Maps Gray Map of Death

For the last week I have been struggling with a perpetually gray Google map on a client site. I had worked with Google Maps API before and not encountered any thing like this. I could add and remove controls, change points, center the map etc.

But the kicker was that Firebug showed that all the images were down loading, I could even switch map types and get a whole new set of images.

GAPDesigns.com

Alan Peabody is a web application developer with a passion for open source.

He spends most of his time working with Ruby, Rails, Linux, XHTML/CSS, analytics and online marketing.

  1. 1 page is tagged with blog
  2. 1 page is tagged with cms
  3. 1 page is tagged with css
  4. 1 page is tagged with google maps
  5. 1 page is tagged with radiant

Blog Archive