Friday, June 25, 2010

Escape Single Quotes in Ruby Strings

Got this from http://snippets.dzone.com/posts/show/880

class String
  def escape_single_quotes
    self.gsub(/'/, "\\\\'")
  end
end 
Usefull when passing strings to javascript. I placed mine in config/initializers

No comments:

Post a Comment