0

I had a question, re: creating nested html tags in Rails, since I am just learning rails.

Basically, I am trying to refactor some code that looks like this:

<a id="myid" href="/mylink">MainLinkText<span>Subtext</span></a>

However, when I use the contact_tag inside a link_to, I can't get it to display the MainLinkText. My code looks like this:

link_to content_tag(:span, "Subtext"), mylink_path, :id => "myid"

But I don't know how to get the "MainLinkText" in there. Is there a clean way of doing this?

Thanks in advance

1 Answer 1

1
link_to "MainLinkText #{content_tag(:span, "Subtext")}".html_safe, mylink_path, :id => "myid"
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks @odiszapc, that worked like a charm! I had tried the interpolation part before I posted my question, but I wasn't doing it right, since the results I got didn't match what I was hoping for (or what your answer provides).
Ok, but one more thing - be carefull with .html_safe, it's not good idea to use this method anywhere...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.