Merb and Datamapper on Ubuntu with XAMPP

The process of setting up Merb and Datamapper can easily derail, these are my experiences of setting them up on Ubuntu with XAMPP.


Setting up stuff on Linux is often a painful experience and this was not an exception, some trial and error took place. First of all, here are some articles that got me started:
Justin Pease’s getting rolling with Merb and Datamapper.
Kacper Cieslas Merb + Datamapper noob quick start.
Paul Berry’s Merb and Datamapper tutorial.

At first I tried to get everything to work on a system that was older than Feisty (I think). That didn’t work, for some reason do_mysql wouldn’t compile properly on that machine. Going with an updated Feisty went fine though.

After that I hit $ merb merb_app expecting this to generate my fresh new Merb application but instead I got “not a recognized bash command”.

Adding:
export PATH=$PATH:/var/lib/gems/1.8/bin:
to the end of .bashrc and relaunching my terminal took care of that problem. The source discussion:

Adding bash commands in Ubuntu.

If you for instance take a look at Kacper’s tutorial you will see an example of a config file for the database setup in Merb. You will see that it lacks a socket, if the socket string to our MySQL database is not there some default socket path will be used, which is probably fine if you used apt-get to install MySQL “normally”. However, my setup is not normal, I use XAMPP so I need a custom path, this is my database.yml:

---
# This is a sample database file for the DataMapper ORM
:development: &defaults
  :adapter: mysql
  :database: merb_app
  :username: root
  :password: 
  :host: localhost
  :socket: /opt/lampp/var/mysql/mysql.sock

:test:
  <<: *defaults
  :database: merb_app

:production:
  <<: *defaults
  :database: merb_app

Launching Merb in my Merb application directory after that enabled Datamapper to connect properly. After that I tried to do the auto_migrate magic that you can find in Paul’s tutorial, but it didn’t work so I just launched phpMyAdmin and created my products table manually:

CREATE TABLE IF NOT EXISTS `products` (
  `id` int(11) NOT NULL auto_increment,
  `name` varchar(255) NOT NULL,
  `price` float NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1

However, doing Product.create(:name => ‘Bananas’, :price => 25.36) in the Merb irb worked, I have no idea why.

Anyway, here is my small test application, and it works which is the only thing that matters in the end I suppose:

Controller:
class HelloWorld < Application
	def index
		@product = Product.first
		render
	end
end

Model:
class Product < DataMapper::Base
	property :name, :string
	property :price, :float
end

View:
<h1>Product: <%= @product.name %> Price: <%= @product.price %></h1>

Articles like Zed’s rant and Rob’s imploding rails post just made me very hesitant regarding rails. Merb feels like the solution to the problems, especially when you read Why Merb? and Why Datamapper?.

Related Posts

Tags: , , , , ,