在 Rails 3 中渲染 Markdown 文本
我想将 markdown 转换为 html。在我看来,我有 markdown(some_text_variable)
但收到错误 undefined method markdown
。
我向 enviroment.rb 添加了 require 'BlueCoth'
并安装了 BlueCloth gem。有人可以帮助我吗?
I want to convert markdown to html. In my views I have markdown(some_text_variable)
but I get the error undefined method markdown
.
I added require 'BlueCoth'
to enviroment.rb and I installed the BlueCloth gem. Can anybody help me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
在你的 Gemfile: 中
不要忘记运行
,当你需要将 markdown 转换为 html 时
,只需使用:你可以在视图中使用它:
In your Gemfile:
and don't forget to run
when you need to convert markdown to html, simply use:
You can use it in a view:
您可以使用 RDiscount
https://github.com/rtomayko/rdiscount
You can use RDiscount
https://github.com/rtomayko/rdiscount
我建议不要使用蓝牙,因为它看起来维护得不太好。
截至目前(2013 年夏季)我发现的最好的东西是 Redcarpet gem:https://github.com /vmg/红地毯
I'd recommend against bluecloth as it doesn't look like it's being upkept that well.
Best thing I've found out there as of now (summer 2013) is the Redcarpet gem: https://github.com/vmg/redcarpet
#markdown
帮助器已在 Rails 3 中删除。您可以复制并粘贴提交中的代码或使用第三方 Gem,例如 formatize。您还必须在
Gemfile
中包含所需的BlueCloth
/RedCloth
/etc gem。The
#markdown
helper was removed in Rails 3.You can copy & paste the code from the commit or use a third party Gem, like formatize. You will also have to include the required
BlueCloth
/RedCloth
/etc gem in yourGemfile
.尝试将以下内容添加到您的
environment.rb
中,而不是 require:在 Rails 3 中,这将位于 Gemfile 中:
该 gem 称为 BlueCloth,但所需的 .rb 文件全部为小写。
确保在添加 config.gem 行后重新启动 Rails。
Try adding the following to your
environment.rb
instead of the require:In Rails 3, this would be in the Gemfile:
The gem is called BlueCloth, but the .rb file that gets required is all lowercase.
Make sure you restart rails after adding the config.gem line.