vendredi 1 juillet 2016

html_safe not working on dynamic prepared string in Rails

I am preparing a url with dynamic query parameters. I have to place "?" character dynamically. But when I form the link string and call html_safe, but its not working.

Here is my code:

sandbox_mode = sandbox_mode? ? "?sandbox_mode=true" : ""
q_link = "<a href='/users/comments#{sandbox_mode}"
q_link += q_link.include?("?") ? "&" : "?"
q_link += "xyz=abx&abc=ttt"

q_link.html_safe

When I did this it shown a string in email, its not preparing link.

When I try like this, it works fine

"<a href='/users/comments?sandbox_mode=true?xyz=abx&abc=ttt</a>".html_safe

Please help where I am wrong.

Aucun commentaire:

Enregistrer un commentaire