سؤال

I have this method in my helper and I'm trying to apply a tag like <strong> anytime I get the text "The winner is"

  def operation_title(operation)
   result = operation_date(operation)
   result << " "
   description = operation.description_ml
   result << "#{description[0..50]}..." if description.size > 53
   result << description unless description.size > 53
  end

I try to add around these lines of code in my method:

    result = "#{description[<strong>The winner is</strong>]}" if description.include?("The winner is")
    result.html_safe

But I can not get the <strong> tag out for my text "The Winner is". What am doing wrong? I am really newbie on ruby.

هل كانت مفيدة؟

المحلول

Try this instead:

result.gsub!('The winner is', '<strong>The winner is!</strong>')
result.html_safe

gsub replaces match by given string.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top