Ruby:2.0.0p0,Rails:3.2.13,红地毯:2.2.2
application_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 %>
但是出现错误:wrong argument type nil (expected String)
,然后我改为<%= markdown(@question.content) %>
,<%= markdown(@question.content.to_s) %>
然后出现这个错误:undefined methodto_html' for "":String
,所以我改为markdown.render(text).to_html.html_safe
在markdown.render(text).html_safe
并且application_help.rb
它只有标题输入字段,内容输入字段已丢失。
我该如何解决这个问题,如果您需要更多信息,请告诉我。