Rails || Merb
January 14th, 2008
After playing around with merb and data mapper over the holidays, I thought a post on some of the differences that I’ve found between rails and merb might be helpful to someone thinking about trying merb out.
If you haven’t already installed merb, check out Jon’s awesome screencast, that should get you started.
Here’s my list1:
| The Rails way | The Merb way |
| script/server | merb |
| script/console | merb -i |
| redirect_to blog_path(@blog) | redirect url(:blog, @blog) |
| respond_to | provides :xml, :js, :yaml |
| format | case content_type |
| render :xml => @post | render @post |
| render :file => ‘public/404.html’, :status => 404 | raise NotFound |
| format.html | only_provides :html, :xml |
| logger | Merb.logger |
| before_filter | before |
| render :partial | partial |
| f.text_field :name | text_control :first_name, :label => ‘First Name’ |
| RAILS_ENV | MERB_ENV post v0.5.0 Merb.environment |
1 This list is by no means a complete list and I can’t guaranty that they won’t change as merb is in active development, but feel free comment with anything I have missed.
6 Responses to “Rails || Merb”
Sorry, comments are closed for this article.






`content_type` merely returns a symbol representing the content-negotiated mime-type, which can be handled with any form of conditional logic. The following is perfectly valid:
Or any other combination or permutation or flow control you can imagine :)
`only_provides` takes x arguments, so `only_provides :html, :xml` is also valid. This is typically just used to over-ride the controller-level settings of provides for a specific action which is different.
also worth noting, post 0.5.0, MERB_ENV is Merb.environment (along with a host of similar constants, which are now attributes of the Merb object).
Hey Stephen,
Thanks for the comment, have updated the post.
Cheers, Matt
Any thoughts on doing a similar post comparing datamapper and activerecord? I too spent my break looking at merb + datamapper and I think datamapper has unbelievable potential. It’s definitely not production-ready, but I can’t wait till it is!
How did you find it?
Hey Bodaniel, There are a few bugs with DataMapper, conditions on associations and count for example, but I like the cleaner syntax. Will do a similar write for DM and AR soon.
Overall I found it very nice to work in, we already use merb/AR in our internal projects and I’m starting a side project of my own in merb/DM. I’d definitely recommend checking it out.
You could also mention:
Rails: request.xml_http_request? Merb: request.xhr?
Tony, i am 99.9% sur rails has request.xhr? as well!