我正在Ruby On Rails中创建一个Twitter克隆,我如何编码它以便'推文'中的'@ ...'变成链接?

Cod*_*own 3 ruby ruby-on-rails

我有点像一个Rails新手,所以请耐心等待我,除了这一部分,我已经找到了大部分应用程序.

mag*_*elm 5

def linkup_mentions_and_hashtags(text)    
  text.gsub!(/@([\w]+)(\W)?/, '<a href="http://twitter.com/\1">@\1</a>\2')
  text.gsub!(/#([\w]+)(\W)?/, '<a href="http://twitter.com/search?q=%23\1">#\1</a>\2')
  text
end
Run Code Online (Sandbox Code Playgroud)

我在这里找到了这个例子:http://github.com/jnunemaker/twitter-app

辅助方法的链接:http://github.com/jnunemaker/twitter-app/blob/master/app/helpers/statuses_helper.rb