Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

link_to with additional html within anchor tag

How do I add additional content to a link when using the link_to helper in Rails?

link_to "Stephen Weber", "index.html" 

creates this:

<a href="index.html">Stephen Weber</a> 

But what if I want to create this?

<a href="index.html">     <h3>Stephen Weber</h3>     <p><strong>You've been invited to a meeting at Filament Group in Boston, MA</strong></p>     <p>Hey Stephen, if you're available at 10am tomorrow, we've got a meeting with the jQuery team.</p>     <p class="ui-li-aside"><strong>6:24</strong>PM</p> </a> 

I'm playing around with jQuery Mobile and this is what is required for formatting content in lists.

like image 859
Jeff B Avatar asked Apr 08 '11 18:04

Jeff B


People also ask

Can anchor tags be nested?

Links and anchors defined by the A element must not be nested; an A element must not contain any other A elements. Since the DTD defines the LINK element to be empty, LINK elements may not be nested either.

How do anchors work in HTML?

The <a> element, or anchor element, it used to create a hyperlink to another webpage or another location within the same webpage. The hyperlink created by an anchor element is applied to the text, image, or other HTML content nested between the opening and closing <a> tags.

How does link_ to work in rails?

Rails is able to map any object that you pass into link_to by its model. It actually has nothing to do with the view that you use it in. It knows that an instance of the Profile class should map to the /profiles/:id path when generating a URL.


1 Answers

You Could do:

 <%= link_to 'index.html', :title => "Some link" do %>      <h3> Stephen Weber </h3>      ...  <% end %> 
like image 63
konus Avatar answered Sep 21 '22 16:09

konus