Ruby on rails 3.1 与红地毯减价合作,打造最佳宝石
对于我的标记文本,我通常对文本内容(@user.content)执行以下操作:Ruby on rails 3.1 与红地毯减价合作,打造最佳宝石,ruby-on-rails-3.1,Ruby On Rails 3.1,对于我的标记文本,我通常对文本内容(@user.content)执行以下操作: 不过我现在用的是最好的宝石 <%= best_in_place(@question, :statement, :path => {:controller => "users", :action => "update"}, :type => :textarea) %> {:controller=>“users”,:action=>“update”},:type=>:textar
不过我现在用的是最好的宝石
<%= best_in_place(@question, :statement, :path => {:controller => "users", :action => "update"}, :type => :textarea) %>
{:controller=>“users”,:action=>“update”},:type=>:textarea)%>
我如何将红毯与此集成?我试过这个:
<%= Redcarpet.new(best_in_place(@question, :statement, :path => {:controller => "users", :action => "update"}, :type => :textarea)).to_html.html_safe %>
{:controller=>“users”,:action=>“update”},:type=>:textarea))。to_html.html_safe%>
然而,产出并不是预期的。最好的自述文件似乎指出了一种解决这个问题的方法,但我不明白,在标题为“使用自定义显示方法”的部分下。有人能给我解释一下我是如何做到这一点的吗?我从来没有使用过最好的宝石,所以我没有尝试过。但根据文档,您应该执行以下步骤:
最佳位置的调用中添加附加参数:display\u as
:display_as
引用的方法课堂问题
require 'redcarpet'
def mk_statement
Redcarpet.new(self.statement).to_html.html_safe
end
您还可以使用带有属性的
display\u,并向其传递一个proc
,如下所示:
<%= best_in_place(@question, :statement, :display_with => proc { |v| Redcarpet.new(v).to_html.html_safe, :path => {:controller => "users", :action => "update"}, :type => :textarea) %>
proc{v|red地毯.new(v).to_html.html_safe,:path=>{:controller=>“users”,:action=>“update”},:type=>:textarea)%>
require 'redcarpet'
def mk_statement
Redcarpet.new(self.statement).to_html.html_safe
end
<%= best_in_place(@question, :statement, :display_with => proc { |v| Redcarpet.new(v).to_html.html_safe, :path => {:controller => "users", :action => "update"}, :type => :textarea) %>