Merb Tips 1

_* this content is now outdated and only applied to Merb 0.9_*

I’m working on a post reporting a recent benchmark I did comparing Rails vs Merb performances for a client’s app.

In the meantime, here are few tricks you might need when using Merb 0.9x

  1. In the init.rb file, uncomment and rename c[:session_id_key] (in the Merb::Config.use block)

  2. In the same block, add c[:log_level] = :debug to set a log level

  3. By default, Merb logs to STDOUT, to log to a file, in the config block add c[:log_file] = Merb.log_path + ‘/development.log’ (note that you need to create the file yourself, Merb won’t do that)

  4. to save your gems locally, do: sudo gem install gem_name -i gems

  5. need basic HTTP auth? it’s now available in core

  6. don’t forget to require any plugins, extra gems you need (such as merb_helpers or merb-assets)

  7. don’t forget to select your ORM before using the generator( so your generated goodies will be adapted to your ORM)

  8. routes are easy to use. In the console (merb -i) type merb.show_routes to see all your named routes

  9. if you want to use link_to, install merb_assets

  10. nested routes example:

1<tt>
</tt>2<tt>
</tt>3<tt>
</tt>4<tt>
</tt><strong>5</strong><tt>
</tt>6<tt>
</tt>




<tt>
</tt>  r.resources <span class="sy">:channels</span> <span class="r">do</span> |channels|<tt>
</tt>    channels.resources <span class="sy">:shows</span> <span class="r">do</span> |shows|<tt>
</tt>     shows.resources <span class="sy">:episodes</span><tt>
</tt>    <span class="r">end</span><tt>
</tt>   <span class="r">end</span><tt>
</tt>

usage:

1<tt>
</tt>2<tt>
</tt>3<tt>
</tt>4<tt>
</tt>




<tt>
</tt>  url(<span class="sy">:channel_shows</span>, <span class="sy">:channel_id</span> => channel)<tt>
</tt><tt>
</tt>  link_to h(channel.description), url(<span class="sy">:channel</span>, <span class="sy">:id</span> => channel)<tt>
</tt>

That’s it for today :)

In the meantime, check this Merb presentation by Ezra and this DataMapper presentation by Wycats


268 Words

2008-04-05

comments powered by Disqus