Ruby on rails 3.2 红地毯-2.2.2不';我不知道内容
Ruby:2.0.0p0,Rails:3.2.13,红毯:2.2.2Ruby on rails 3.2 红地毯-2.2.2不';我不知道内容,ruby-on-rails-3.2,redcarpet,Ruby On Rails 3.2,Redcarpet,Ruby:2.0.0p0,Rails:3.2.13,红毯:2.2.2 application\u helper.rb def markdown(text) markdown_render = Redcarpet::Render::HTML.new(:hard_wrap => true, :n
application\u helper.rb
def markdown(text)
markdown_render = Redcarpet::Render::HTML.new(:hard_wrap => true, :no_styles => true)
markdown = Redcarpet::Markdown.new(markdown_render, :autolink => true, :no_intro_emphasis => true)
markdown.render(text).to_html.html_safe
end
app/views/questions/new.html.erb
<%= simple_form_for @question do |f| %>
<%= f.input :title, :input_html => { :class => "span6" } %>
<%= markdown(@question.content) %>
<%= f.button :submit, :class => 'btn-primary' %>
<%= link_to 'Cancel', @question.id.blank? ? questions_path : question_path(params[:question]), :class => "btn btn-danger" %>
<% end %>
{:class=>“span6”}%>
“btn主节点“%”
“btn btn危险”%>
但是出现了错误:错误的参数类型nil(预期字符串)
,然后我将
更改为
,然后出现了此错误:未定义的方法改为“:String
,所以我将markdown.render(text).改为\u html.html\u safe
改为markdown.render(text).html_safe
在应用程序_help.rb
中,它只有标题输入字段,内容输入字段已丢失。我如何解决这个问题,如果您需要更多信息,请告诉我 尝试以下帮助程序:
def markdown(text)
if text.blank?
nil
else
markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, :autolink => true, :space_after_headers => true)
markdown.render(text)
end
end
这在Rails 4.1.0上对我很有效 将以下内容放入app/helpers/application_helper.rb:
def markdown(text)
if text.blank?
nil
else
markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, :autolink => true, :space_after_headers => true, filter_html: true, hard_wrap: true, link_attributes: { rel: 'nofollow', target: "_blank" }, space_after_headers: true, fenced_code_blocks: true, superscript: true, disable_indented_code_blocks: true)
markdown.render(text).html_safe
end
end
我想唯一的区别是把
.html\u安全
放在最后我不是一个红地毯用户。我不得不猜测。请尝试我刚刚编辑的新版本。您似乎不需要使用html部分。是的,您是对的。我已经删除了to_html部分,它可以正常工作。