Ruby: 2.0.0p0 , Rails: 3.2.13, redcarpet: 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 method
to_html' for "":String,然后又将application_helper中的
markdown.render(text).to_html.html_safe改为
markdown.render(text).html_safe`后,没有了 content 输入框,只有 title 输入框。
求指导。。