Automate Everything: Ruby, Linux and other hints, tips and tricks.

How I got Mephisto working on Dreamhost

As long as Dreamhost supports Phusion Passenger now, installing the Ruby on Rails blog engine Mephisto should be an easy task. However, I found this trickier than I expected. I followed the basic instructions and I was getting the following error on my log/production.log:

ActionView::TemplateError (can't convert nil into String) on line #6 of app/views/admin/design/_sidebar.rhtml:
3: <p>Modify a template by selecting it from the list below.  Add a new layout by creating a Liquid template with an
4:   *_layout suffix (e.g custom_layout).</p>
5: <ul id="attachments">
6:   <% @theme.templates.template_types(@theme.extension).each do |template| -%>
7:     <li><%= link_to h(template), url_for_theme(:controller => 'templates', :action => 'edit', :filename => template) %></li>
8:   <% end -%>
9:   <% @theme.templates.custom(@theme.extension).each_with_index do |template, i| -%>
 
    /home/manuelmorales/mephisto/app/models/templates.rb:6:in `+'
    /home/manuelmorales/mephisto/app/models/templates.rb:6:in `template_types'
    /home/manuelmorales/mephisto/app/models/templates.rb:6:in `collect'
    /home/manuelmorales/mephisto/app/models/templates.rb:6:in `template_types'
    ....

The problem is that, in spite of the right tzinfo gem already comes with Mephisto, Phusion Passenger is ignoring local gems, taking the old version of tzinfo that Dreamhost provides. The solution is simple: Force Rails to load exactly that gem adding the following to your config/environment.rb.

...
require '/home/<yourusernamehere>/mephisto/vendor/gems/tzinfo-0.3.12/lib/tzinfo'
...

And restarted the server:

touch tmp/restart.txt

Visited a working page of the blog twice to force the restart to make effect and tzinfo error gone.

In case that you are trying to install another application that doesn’t already come with the gem you have to override, you will have to install it locally before forcing Rails to load it. Directions about how to install gems locally in the Dreamhost wiki.

But that wasn’t enough. Then I was getting the following error:

ActionView::TemplateError (attempted to output tainted string: <a href="mailto:email@domain.com">email@domain.com</a>) on line #14 of app/views/admin/sites/show.rhtml:
11: <% form_for :site, :url => { :action => "update", :id => @site } do |f| -%>
12: <%= f.error_messages %>
13: <div id="general" class="setgroup">
14:   <h3><%=h @site.title %> <small>(<%= mail_to @site.email %>)</small></h3>
15:   <dl class="setform">
16:             <dt><label for="site_host">Host</label></dt>
17:             <dd><%= f.text_field :host %></dd>
 
    /home/manuelmorales/mephisto/vendor/gems/emk-safe_erb-0.1.1/lib/safe_erb/common.rb:48:in `concat_unless_tainted'
    /home/manuelmorales/mephisto/app/views/admin/sites/show.rhtml:14
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_view/helpers/form_helper.rb:313:in `fields_for'
    ...

As said here on the Mephisto blog:

One debugging tip: If you see an error like ActionView::TemplateError (attempted to output tainted string), you’ve run afoul of SafeERB and you probably need to insert an h(…) somewhere. Don’t hesitate to ask for help on #mephisto.

That’s it. I had to go to file app/views/admin/sites/show.rhtml, line 14, and modify this:

<h3><%=h @site.title %> <small>(<%=mail_to @site.email %>)</small></h3>

to surround the @site.email with h():

<h3><%=h @site.title %> <small>(<%=mail_to h(@site.email) %>)</small></h3>

And here is it. Fully working now! : )

You can follow any responses to this entry through the RSS 2.0 feed.