Archive for 'Database'

Bundle Install – missing mysql.h

If you’re seeing the following error: The way I was able to resolve it was to follow Boonedocks.net, since I’m also using MAMP for its MySQL Database instance. The only difference is that I already had MAMP 1.9.4 installed and so I had to download the MAMP_components_1.9.dmg which contains the mysql-5.1.44 source code. MAMP 1.9.4 [...]

Using lambda with named scopes in Rails 3

You can define an ActiveRelation named scope inside your model Address, for example, like so:

ActiveRecord destroy method

Once you destroy a record, the object becomes frozen. Call the frozen? method on the referenced object before and after calling destroy to see the difference. If you try to manipulate the object after the object is ‘frozen’, you’ll get a TypeError: can’t modify frozen hash

Installing, Configuring and Troubleshooting PostgreSQL 9.0 in Rails 3 on OS X

The following may apply to other versions of PostgreSQL as well but I’m using version 9.0. I initially tried to install PostgreSQL via MacPorts but after running into issues I describe below, I ended up installing it via the Mac OS X package. If you want to skip issues I ran into with my macports [...]

Handling 404s when RecordNotFound, UnknownAction and RoutingError

When handling 404s, you want to display the 404 page and return HTTP status 404 when a particular record is not found, the action requested is unknown or if there is a routing error. Add the following to your application_controller.rb file, towards the end:

SET data type in MySQL and ActiveRecord

I figured out something cool which solves a common database design problem. However, I’m not sure if this is supported in ActiveRecord since the SET data type does not exist in all databases. Let’s say each record in a table has zero or more properties and your set of properties is pre-defined. How would you [...]

Dealing with Money in Rails

In process of determining how to handle fields such as price, in Rails, I’ve conducted some research. There seems to be a debate on whether to use decimal or integer as the price field. In case of where integer data types are used, the integer actually will store the price in cents. One argument for [...]

Creating a MySQL Database from Terminal or Command Line

The following assumes you have a successful installation of MySQL on OS X or Linux: Create MySQL Database To Test the Connection