The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Reusing Rails 2.2.2 strip_tag view helper

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Vincent Woo

Posts: 30
Nickname: vwoo
Registered: Sep, 2008

Vincent Woo is a Ruby on Rails enthusiast.
Reusing Rails 2.2.2 strip_tag view helper Posted: Mar 21, 2009 10:43 AM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Vincent Woo.
Original Post: Reusing Rails 2.2.2 strip_tag view helper
Feed Title: Undefined Range
Feed URL: http://www.undefinedrange.com/categories/ruby-on-rails.rss
Feed Description: Interesting things I experience with Ruby on Rails.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Vincent Woo
Latest Posts From Undefined Range

Advertisement

In one of my Rails projects, I have this one class that strips HTML from some user submitted text. Instead of reinventing the wheel, I reused the Rails view helper strip_tags() by including the relevant module:

  class Presenter
    include ActionView::Helpers::SanitizeHelper
  end

This worked great until I upgraded the Rails framework to v2.2.2. The following error began appearing:

  undefined method `full_sanitizer' for Presenter:Class

Turned out it was easy to fix. Looking at the strip_tags method in actionpack/lib/action_view/helpers/sanitize_helper.rb:

def strip_tags(html)
  self.class.full_sanitizer.sanitize(html)
end

It’s trying to access a class method that doesn’t exist in Presenter. While I included the instance methods, now I also have to extend the necessary class methods.

  class Presenter
    include ActionView::Helpers::SanitizeHelper
    extend ActionView::Helpers::SanitizeHelper::ClassMethods
  end

Now all is good.

Read: Reusing Rails 2.2.2 strip_tag view helper

Topic: RubyLearning's Sponsor: 1st Easy Limited Previous Topic   Next Topic Topic: Ruby Class and Rails Plugin Trees With Hirb

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use