在我的Ruby on Rails应用程序中是否可以使用ruby进行降价?我正在使用RedCarpet gem,并且在我的应用程序控制器中有以下内容。红宝石可以降价吗? Ruby on Rails应用程序
class ApplicationController < ActionController::Base
before_filter :get_contact_info
private
def get_contact_info
@contact = Contact.last
end
end
下面是联系的模式
create_table "contacts", :force => true do |t|
t.string "phone"
t.string "email"
t.string "facebook"
t.string "twitter"
end
所以我有联系信息的工作,有没有办法,我可以告诉降价渲染渲染<%= @ contact.phone% >作为@ contact.phone的值而不是纯文本?或者我需要使用其他方法,然后降价呢?
编辑1:
渲染降价这里:
应用程序/佣工/ application_helper.rb
def markdown(text)
options = [:hard_wrap, :filter_html, :autolink, :no_intraemphasis]
Redcarpet.new(text, *options).to_html.html_safe
end
应用程序/视图/网站/ show.html.erb
<%= markdown(site.description) %>
编辑2:
这是我的解决方案,谢谢。我将你的代码集成到我的标记助手中,这似乎工作到目前为止。
def markdown(text)
erbified = ERB.new(text.html_safe).result(binding)
options = [:hard_wrap, :filter_html, :autolink, :no_intraemphasis]
Redcarpet.new(erbified, *options).to_html.html_safe
end
你是如何渲染降价? – 2012-04-13 23:23:26
@Sergio Tulentsev我编辑了一些信息,让我知道你是否需要更多。谢谢! – ruevaughn 2012-04-13 23:28:07