The Merbist

Merb & Rails 3 news - consulting - training

Archive for the ‘Tutorial’ Category

Get on Merb Edge pre 1.0

Posted by Matt Aimonetti On October - 4 - 2008 6 COMMENTS

Merb 1.0 is almost ready to be pushed out and you might be impatient to start playing with some of the goodies not yet available in the latest stable release. Before getting started, you should know that not everything has been ironed out yet so don’t expect to have a fully stable Edge.

The easiest way to get started requires that you have git installed as well as a gem called thor.

I let you take care of installing git on your machine, Ruby dev without git became quite challenging since GitHub started ruling the Ruby OSS world.

sudo gem install wycats-thor -s http://gems.github.com
Hops, used primarily as a flavoring and stability agent in beer, and also in other beverages and in herbal medicine.

Hops, used primarily as a flavoring and stability agent in beer, and also in other beverages and in herbal medicine.

Thor is a sort if mix between rake, sake with a better argument parser and based on Ruby classes.

Thor on its own won’t be very helpful, we need some thor tasks.

Create a folder where you want to store Merb’s source code and cd in it.

Once there download the latest merb thor tasks:

curl -L http://merbivore.com/merb.thor > merb.thor

You can now look at the available task by doing

thor -T

Read the rest of this entry »

problems with urls in Merb HEAD?

Posted by Matt Aimonetti On September - 30 - 2008 ADD COMMENTS

I actually run into a small problem when updated an older Merb app. Here was how my router looked like:

Merb::Router.prepare do |r|
  r.resources :channels do |channels|
    channels.resources :shows do |shows|
      shows.resources :episodes
    end
  end
end

But after updating to the latest version of Merb, I got links looking like:

http://localhost:4000/channels/#<Channel:0x27b7300>/shows

The first thing to do is to read Carl’s wiki about the latest Router changes.

Carl explains that things got cleaned up in the router code and my routes should now look like:

Merb::Router.prepare do |r|
  r.resources :channels do
    resources :shows do |shows|
      resources :episodes
    end
  end
end

However that won’t be enough.. You see my url used to look like that:

url(:channel_shows, :channel_id =&gt; channel)

Now I can simplify it to:

url(:channel_shows, channel)

That still won’t fix the problem, since the real problem comes from the fact that I was on Merb HEAD but not DataMapper HEAD. Updating DM clears things up. That’s the price to pay to be on HEAD ;)

FYI the problem comes from the fact that DM doesn’t add a to_params method to its objects. Rails users might recognize that method used to convert an object into a string to create a route, something not really ORM agnostic and frowned upon by the DM/Merb teams.

Merb lets you specify the param to use for your routes using the identify method. Read Carl’s wiki page for more cool stuff and see how to create some cool stuff like url slugs etc..

Note that even if you are using ActiveRecord, you’ll need to update merb_activerecord as the new identify rules were updated in the ORM plugins.

Write your own custom DataMapper adapter

Posted by Matt Aimonetti On September - 29 - 2008 6 COMMENTS

If you read this blog, you probably know that Merb’s best ORM friend is DataMapper.

compounds in basil oil have potent antioxidant and is used for supplementary treatment of stress

compounds in basil oil have potent antioxidant and is used for supplementary treatment of stress

Merb works very well with ActiveRecord and Sequel but most of the Merbivores get excited about DataMapper.

DataMapper has a lot of cool stuff going for it. I’m planning on writingi few articles about what I particularily like with DM and some of the misconceptions.

I’m going to give a talk about DataMapper during MerbCamp and something I want to cover is the fact that you can write DM adapters for virtually anything. From an adapter for couchdb (available in dm-more) to an adapter for SalesForce API. That’s the kind of stuff that gets me excited, a bit like what Ambition does but built-in in DM.

So, I decided to take some advise from Yehuda and dkubb and wrote my own adapter for Google Video. I had just finished a gem to retrieve google videos for a given google user and thought it would be a perfect exercise to mix a http-scraper with a DM adapter.

Read the rest of this entry »

Deploying a bundled merb app (merb 0.9.7+)

Posted by Matt Aimonetti On September - 23 - 2008 8 COMMENTS

Since Merb 0.9.7 the Merb team decided to change the way you can bundle an app. Until 0.9.7 you would use the merb-freezer plugin which was supporting git submodules and gems. The only problem was that you still had to install merb-freezer on your server and it had to stay in sync with your app… kinda lame :(

Ginger

Ginger roots, great for deployment issues

Instead, after a lot of discussions, we decided to add this feature to merb-core and let you bundle all your dependencies in a bundled gem folder. No more support for git submodules as they are hard to keep track of and don’t handle dependencies very well (not at all).

The new freezing strategy is very well described in this merbunity article. However it doesn’t really explain how to deploy a bundled app.

So let’s imagine for a second that we bundle our app, generated the scripts needed to start merb/rake etc…

Read the rest of this entry »