简体   繁体   English

Rails 2.3.11-> 3.2.3具有正则表达式的简单gsub无法正常工作

[英]Rails 2.3.11 -> 3.2.3 simple gsub with regex does not work

I tried to upgrade my Rails 2.3.11 application to Rails 3.2.3, but this function in ApplicationHelper does not work properly anymore in the browser (in Rails console everything is fine): 我试图将Rails 2.3.11应用程序升级到Rails 3.2.3,但是ApplicationHelper中的此功能在浏览器中不再正常工作(在Rails控制台中一切正常):

def basic_markup(text)
  if text
    text.gsub!(/(\A|\s|\[|\()_(.+?)_/iu, '\1<em>\2</em>')
    text.gsub!(/(\A|\s|\[|\()#(.+?)([^&])#/iu, '\1<del>\2\3</del>')
    text.gsub!('->', '→')
    text.gsub!('<-', '←')
  end
  text
end

text = '#strikeout# normal _italic_'
puts basic_markup(text)
# Rails 2.3.11
# => "<del>strikeout</del> normal <em>italic</em>"
# Rails 3.2.3
# => "#strikeout# normal <em>italic</em>"

Sample on Rails 2.3.11: http://moly.hu/karcok/150362 Rails 2.3.11上的示例: http : //moly.hu/karcok/150362

The same on Rails 3.2.3: http://moly.hu:3000/karcok/150362 在Rails 3.2.3上也是如此: http ://moly.hu:3000/karcok/ 150362

What's wrong? 怎么了?

Copying the answer from the comments in order to remove this question from the "Unanswered" filter: 复制评论中的答案,以便从“未回答”过滤器中删除此问题:

Frost suggested an upgrade: 弗罗斯特建议升级:

Update to my comment above: I just tried creating a new rails 3.2.3 project, put that method in the application_helper and calling it from a view with the same text, and works just fine. 更新上面的评论:我刚刚尝试创建一个新的Rails 3.2.3项目,将该方法放在application_helper ,并从具有相同文本的视图中调用它,并且效果很好。 I think you're missing something somewhere else. 我认为您在其他地方缺少某些东西。

Nagy Bence confirmed: 纳吉·本斯(Nagy Bence)确认:

Problem solved, maybe Rails' simple_format has changed between 2.3.11 and 3.2.3, but now it runs correctly. 问题解决了,也许Rails的simple_format在2.3.11和3.2.3之间进行了更改,但是现在可以正常运行了。 Thanks for the comments! 感谢您的评论!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM