我在我的网站上有用户生成的评论.如果用户在评论中添加了一个URL,我希望将其格式化为链接并实际链接到该URL.我怎么做?
Sim*_*tti 18
Rails有一个auto_link文本助手.
auto_link("Go to http://www.rubyonrails.org and say hello to david@loudthinking.com")
# => "Go to <a href=\"http://www.rubyonrails.org\">http://www.rubyonrails.org</a> and
# say hello to <a href=\"mailto:david@loudthinking.com\">david@loudthinking.com</a>"
auto_link("Visit http://www.loudthinking.com/ or e-mail david@loudthinking.com", :link => :urls)
# => "Visit <a href=\"http://www.loudthinking.com/\">http://www.loudthinking.com/</a>
# or e-mail david@loudthinking.com"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2742 次 |
| 最近记录: |