[LRUG] Rails 2.2 Haml filter problem - production only

Andrew Stewart boss at airbladesoftware.com
Wed Nov 19 02:06:14 PST 2008


Morning El Rug,

I have a custom Haml filter in my Rails 2.2 app which works when I run  
the app in development but not in production.

This did work in production before I upgraded from Rails 2.1 to 2.2.   
I presume that Rails changed the way it loads, er, stuff in production  
between 2.1 and 2.2.  Does anybody know what this might be?  (I asked  
the Haml list but they weren't sure.)

I'm using Haml 2.0.4 and Rails 2.2.1.

Here's what I see when I try to fire up the app in production:

** Starting Mongrel listening at 0.0.0.0:3000
** Starting Rails with production environment...
/path/to/my/app/views/comments/_comment.html.haml:6: Filter  
"smartypants" is not defined. (Haml::Error)
	from /usr/local/lib/ruby/gems/1.8/gems/haml-2.0.4/lib/haml/ 
precompiler.rb:711:in `start_filtered'
	from /usr/local/lib/ruby/gems/1.8/gems/haml-2.0.4/lib/haml/ 
precompiler.rb:217:in `process_line'
	from /usr/local/lib/ruby/gems/1.8/gems/haml-2.0.4/lib/haml/ 
precompiler.rb:152:in `precompile'
	from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.2.1/lib/ 
active_support/dependencies.rb:144:in `each_with_index'
	from /usr/local/lib/ruby/gems/1.8/gems/haml-2.0.4/lib/haml/ 
precompiler.rb:118:in `each'
	from /usr/local/lib/ruby/gems/1.8/gems/haml-2.0.4/lib/haml/ 
precompiler.rb:118:in `each_with_index'
	from /usr/local/lib/ruby/gems/1.8/gems/haml-2.0.4/lib/haml/ 
precompiler.rb:118:in `precompile'
	from /usr/local/lib/ruby/gems/1.8/gems/haml-2.0.4/lib/haml/engine.rb: 
100:in `initialize'
	 ... 35 levels...
	from /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/../lib/ 
mongrel/command.rb:212:in `run'
	from /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/ 
mongrel_rails:281
	from /usr/local/bin/mongrel_rails:19:in `load'
	from /usr/local/bin/mongrel_rails:19

My filter code looks like this:

lib/smarty_pants.rb:

   module Haml
     module Filters

       # Forces RDiscount to process with Smarty Pants.
       module SmartyPants
         include ::Haml::Filters::Base
         lazy_require 'rdiscount'

         def render(text)
           ::RDiscount.new(text, :smart).to_html
         end
       end
     end
   end

And I load it with this line at the end of my config/environment.rb:

   require 'smarty_pants'

I use it in my views, such as the one mentioned in the stacktrace,  
like this:

app/views/comments/_comment.html.haml:

   %div[comment]
     %h3== #{link_to comment.member.first_name, comment.member} said  
#{time_ago_in_words comment.created_at} ago

     = image_tag comment.member.portrait.url(:thumb), :class => 'member'

     :smartypants
       #{comment.body}

Thanks in advance.

Cheers,
Andy Stewart

-------
http://airbladesoftware.com





More information about the Chat mailing list