samedi 18 avril 2020

Rails - How to avoid inserting the html in method

I have a method in my project to show the title of books and a followed icon in the table. The method is:

def title_and_follow()
  "#{h.link_to object.title, h.show_book_path(object.uuid)}
   #{h.follow_icon(user, object)}".html_safe
end

It works fine and it shows something like "Harry Potter [followed_icon]" in my table. However, I wonder is there any way to avoid inserting HTML directly in the method? Is there a more elegant way to do that?

Aucun commentaire:

Enregistrer un commentaire