BlueCloth不适用于Rails 3 [英] BlueCloth isn't working with Rails 3

查看:153
本文介绍了BlueCloth不适用于Rails 3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

BlueCloth是否与Rails 3兼容?我不能让它工作,也许有人使用它?



在要求'bluecloth'后,应该有一个名为'markdown'的助手可用,但这似乎并没有可用。

解决方案

我正在升级应用程序到rails3,它对我来说工作得很好。我在模板中使用了一个名为format的助手函数,尽管下面的代码也提供了一个markdown函数(在rails3中,您必须使用raw())来使用它。下面是我的[project] /app/helpers/application_helper.rb的内容。

  module ApplicationHelper 
#显示。
def格式(文本)
清理(降价(文本))
结束

#使用Markdown处理文本。
def markdown(text)
BlueCloth :: new(text).to_html
end
end

就像以前的海报说的那样,你还需要

  gem'bluecloth' 

存储在[project] / Gemfile中。我的模板如下所示:

 < p><%= format @ post.body%>< / p> 

使用减价功能可以:

 < p><%= raw(markdown(@ post.body))%>< / p> 

所以我使用格式函数。不管你想要的重命名这些功能。

Is BlueCloth compatible with Rails 3? I can't make it work, maybe someone uses it?

There is supposed to be a helper called 'markdown' available in the views after requiring 'bluecloth', but this doesn't seem to be available.

解决方案

I'm upgrading an app to rails3 right now and it worked fine for me. I use a helper function called "format" in templates though the code below also provides a markdown function (in rails3 you'll have to use that with raw()). Here's the contents of my [project]/app/helpers/application_helper.rb

module ApplicationHelper
  # Format text for display.                                                                    
  def format(text)
    sanitize(markdown(text))
  end

  # Process text with Markdown.                                                                 
  def markdown(text)
    BlueCloth::new(text).to_html
  end
end

Like a previous poster said, you'll also need

gem 'bluecloth'

in your [project]/Gemfile. My template looks like:

<p><%= format @post.body %></p>

With the markdown function it would be:

<p><%= raw(markdown(@post.body)) %></p>

So I use the format function. Rename the functions however you want.

这篇关于BlueCloth不适用于Rails 3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆