Merb and Datamapper on Ubuntu with XAMPP

Table of contents for Investigating Merb and Datamapper

  1. Merb and Datamapper on Ubuntu with XAMPP
  2. Registration form with Merb and Datamapper

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?.

These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • blogmarks
  • Reddit
  • Simpy
  • StumbleUpon
  • Technorati
  • DZone
  • Ma.gnolia

Related Posts

Tags: , , , , ,

4 Responses to “Merb and Datamapper on Ubuntu with XAMPP”

  1. Finn Higgins Says:

    I can’t help but think you’re making life a little tricky for yourself. Getting LAMP going on Ubuntu is a piece of cake - tasksel does the job for me, along with apt-get install phpmyadmin - so there’s really very little need for XAMPP. And if you stay on the packaged path then it’s just a question of basically installing every single /^lib.*ruby$/ package (and a bunch of *-dev packages to get the required headers to compile C extensions) and all seems to work out pretty well.

    Getting Merb and Datamapper working on Gutsy at home was just a matter of following their installation instructions. Most of the Ubuntu/Ruby woes come from the sheer number of packages that the essentials are broken up across.

  2. Henrik Says:

    I didn’t have any problems either on Feisty with the gem installations, just that missing path variable. As far as XAMPP goes I use it because the default LAMP that my Linux admin installs all the time (on Suse) runs older versions of a PHP that in addition lacks certain extensions which can be a mess to install. XAMPP has got everything up and running out of the box. However, I don’t doubt that getting the default LAMP running on Ubuntu is a piece of cake, the question is, does it have extensions like pdo_mysql compiled per default nowadays?

  3. Rene Says:

    Servus,

    I didn’t know that you had a website … interessting stuff.

    Prost René

  4. Henrik Says:

    I just did a install on my new laptop with Gutsy and I had the same compile problems again with errors happening in the “compiling native extensions” stage of the gem installs of for instance do_mysql, datamapper and do_postgres. So I fired up synaptic and did a search for “libruby”, browsing through the list and installing the most likely candidates that might help solved the problem.

    Seems like headers are needed too, i.e. files that can be found in synaptic by searching for for instance “ruby-dev”, “mysql-dev” and “dev-8.2″ (postgres).

Leave a Reply