I am using Intype:
I have a problem with this:
def convert_html_entities(text)
text = text.gsub(/["]/, '"')
end
The Intype colors it all green because there is missing a “
I have tried this solution it removed all the green text and the code appeared normal:
def convert_html_entities(text)
text = text.gsub(/['"']/, '"')
end
But it just gave an error in view:
undefined method `convert_html_entities' for #<XmlController:0x448cef0>
Rails.root: C:/Rails/kimnew
Application Trace | Framework Trace | Full Trace
lib/update_xml.rb:21:in `block in update_xml'
lib/update_xml.rb:19:in `update_xml'
app/controllers/xml_controller.rb:21:in `test'
Apparently you did not define
convert_html_entitiesas an instance method of XmlController, so you can’t use it as one.Another problem with your code is that reassigning a method parameter, doesn’t have any effect on the outside. So
text = text.gsub(/['"']/, '"')is the same astext.gsub(/['"']/, '"'). If you want to mutate your argument, you need to usegsub!. That being said: Don’t mutate method arguments. That’s bad style.