0

Hi i have tried almost everything and cant get this to work. The title.capitalize part doesnt get displayed. I tried using "+" but then i get error about expecting end keyword

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

Does anyone have a idea how to solve this ?

minohimself
  • 496
  • 3
  • 9
  • A Ruby block returns the value of the last line in that block. In this case, `title.capitalize` isn't the last line so its value isn't returned. – jkdev Dec 13 '15 at 09:50

2 Answers2

1

Perhaps string interpolation to get both parts into the link text string? Switched to single quotes and curly braces on the block for clarity in the nested usage.

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
Ed Allen
  • 86
  • 7
1

Thank you Ed based on it i was able to do this

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
minohimself
  • 496
  • 3
  • 9