ruby-on-railsruby-on-rails-4actionviewhelper

rails helper nested content_tag with span inside link_to


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 ?


Solution

  • 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