0

嗨,我几乎尝试了所有方法,但无法使其正常工作。title.capitalize零件不显示。我尝试使用“+”,但随后出现关于期望 end 关键字的错误

def mailbox_section(title, current_box, opts = {})
  content_tag :li, opts do 
    link_to(conversations_path(box: title.downcase), html_opts = {}) do
      title.capitalize
      content_tag :span, :class => "badge" do  
        "2" 
      end
    end
  end     
end

有谁知道如何解决这个问题?

4

2 回答 2

1

也许字符串插值将两个部分都放入链接文本字符串?为了清楚地嵌套使用,在块上切换到单引号和大括号。

def mailbox_section(title, current_box, opts = {})
  content_tag :li, opts do 
    link_to(conversations_path(box: title.downcase), html_opts = {}) do
      "#{title.capitalize} #{ content_tag :span, :class => 'badge' {'2'} }" 
    end
  end     
end
于 2015-09-03T21:00:14.097 回答
1

谢谢 Ed 基于它我能够做到这一点

def mailbox_section(title, current_box, opts = {})
  content_tag :li, opts do 
    link_to(conversations_path(box: title.downcase), html_opts = {}) do
  "#{title.capitalize} #{content_tag :span, :class => 'badge' do '2' end}".html_safe
    end
  end  
end
于 2015-09-04T13:17:29.257 回答