Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

uninformative error message when using 'markdown' helper without bluecloth gem

#3706

If you happen to use the markdown helper, like so:

<%= markdown(post.body) %>

You get a pretty uninformative error message:

ActionView::Template::Error (uninitialized constant ActionView::Helpers::TextHelper::BlueCloth) on line #4 of /Users/technicalpickles/code/scratch/rails-3-blog/app/views/posts/_post.html.erb:
1: <h2><%= link_to post, post %></h2>
2: 
3: <div id="<%= dom_id(post) %>" class="<%= dom_class(post) %>">
4:   <div class="body"><%= markdown(post.body) %></div>
5: 
6:   <ul class="actions">
7:     <li><%= 'Not' unless post.published? %> Published</li>

    app/views/posts/_post.html.erb:4:in `_render_template_887285710_17704920_230336'
    app/views/posts/show.html.erb:1:in `_render_template__976704918_17747910_0'
    app/controllers/posts_controller.rb:18:in `show'

Fortunately, I'm familiar enough with markdown and bluecloth to know it needs the bluecloth gem, so I'd add this to Gemfile:

gem 'bluecloth'

This doesn't really fix the problem. I double checked that BlueCloth is defined by bluecloth.rb, and it is.

The only way I was able to get it to work was:

<% require 'bluecloth' %>
<%= markdown(post.body) %>

I would have guessed this would have happened by adding it to Gemfile, or at latest, inside the markdown helper.

Reported by Josh Nichols · January 16th, 2010 @ 05:38 AM

State: resolved
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. Josh Nichols
    Josh Nichols
    • Tag changed from action_view, markdown, rails3 to action_view, bugmash, markdown, rails3

    January 16th, 2010 @ 05:38 AM

  2. Ravil Bayramgalin
    Ravil Bayramgalin

    Specifying gems in Gemfile doesn't require them automatically. You always need to require them manually, i prefer to do it in initializer.

    January 16th, 2010 @ 08:24 AM

  3. Josh Nichols
    Josh Nichols

    That matches the behavior I'm seeing, but contradicts bundler's documentation:

    # Don't auto-require this gem.
    gem "rspec-rails", "1.2.9", :require_as => nil
    
    # Require something other than the default.
    gem "yajl-ruby", "0.6.7", :require_as => "yajl/json_gem"
    

    I did try specifically using @:require_as@, but that didn't work either.

    January 16th, 2010 @ 04:38 PM

  4. Prem Sichanugrist (sikachu)
    Prem Sichanugrist (sikachu)
    • State changed from new to resolved

    Current master and 3.0.0.beta does automatically require those gems now. I think this can be closed :)

    February 11th, 2010 @ 03:46 PM

  5. Rolando Murillo
    Rolando Murillo

    I've got the same problem. But I noted that I just need to restart the app to apply the changes within Gemfile.

    June 29th, 2010 @ 08:00 AM

  6. Rolando Murillo
    Rolando Murillo

    I've got the same problem. But I noted that I just need to restart the app to apply the changes within Gemfile.

    June 29th, 2010 @ 08:00 AM