Ruby 红地毯标记呈现两个不同的文本区域

Ruby 红地毯标记呈现两个不同的文本区域,ruby,ruby-on-rails-3,ruby-on-rails-4,markdown,redcarpet,Ruby,Ruby On Rails 3,Ruby On Rails 4,Markdown,Redcarpet,我想我遗漏了什么 我让渲染器与原始文本区域(内容)一起工作了一段时间,现在向模型(主体)添加了一个新列。我已经添加了所有内容,表单工作正常,视图显示了主体输入,但标记不会呈现 这是我的应用程序助手: def markdown(content) @markdown ||= Redcarpet::Markdown.new(Redcarpet::Render::HTML, autolink: true, space_after_headers: true, fenced_code_blocks: t

我想我遗漏了什么

我让渲染器与原始文本区域(内容)一起工作了一段时间,现在向模型(主体)添加了一个新列。我已经添加了所有内容,表单工作正常,视图显示了主体输入,但标记不会呈现

这是我的应用程序助手:

def markdown(content)
 @markdown ||= Redcarpet::Markdown.new(Redcarpet::Render::HTML, autolink: true, space_after_headers: true, fenced_code_blocks: true)
 @markdown.render(content)
end

def markdown(body)
 @markdown ||= Redcarpet::Markdown.new(Redcarpet::Render::HTML, autolink: true, space_after_headers: true, fenced_code_blocks: true)
 @markdown.render(body)
end

def title(page_title)
 content_for :title, page_title.to_s
end
我的观点是:

=title @portfolio.title 

.container.pushdown.img-responsive
 .row
  .col-md-2
        %br
        %p= link_to 'Back', portfolios_path
    .col-md-8
        %h2
            = @portfolio.title

        %p
            =markdown(@portfolio.body).html_safe
        %p
            =markdown(@portfolio.content).html_safe
        %br
        %br
我得到以下错误:

wrong argument type nil (expected String)

markdown
方法需要一个字符串。如果使用
nil
调用它,它将抛出此错误

您可能希望将代码更改为类似以下内容以处理
nil
值:

def markdown(string)
  @markdown ||= Redcarpet::Markdown.new(Redcarpet::Render::HTML, autolink: true, space_after_headers: true, fenced_code_blocks: true)
  @markdown.render(string.to_s)
end

此外,您有两个相同的方法。您可以删除其中一个

错误可能来自

=title @portfolio.title
与降价渲染无关。函数调用的预期签名为:

def title(page_title)

另外,+1表示有两个相同的方法(第一个方法简单地被第二个方法覆盖)。

谢谢,我还在学习(显然)。感谢你的回答。