Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails and the <span> tag

Tags:

I'm fairly new to Ruby on Rails, and I'm attempting to create some fancy CSS buttons using the "sliding doors" technique. I have it almost working, but I feel like there has to be a better way to handle the tags for a link.

The way I'm currently doing it:

 <%= link_to '<span>New car</span>', {:action => "new"}, :class=>"button" %> 

This isn't terrible, per se, but I would like to know if this is the best way to handle span tags in RoR.

like image 284
Zachary Wright Avatar asked Apr 21 '10 18:04

Zachary Wright


People also ask

What is the role of the span tag?

Definition and Usage. The <span> tag is an inline container used to mark up a part of a text, or a part of a document. The <span> tag is easily styled by CSS or manipulated with JavaScript using the class or id attribute.

What is difference between SPAN tag and P tag?

<p> and <div> are block elements by default. <span> is an inline element. Block elements start and end with a new line in the browser while inline elements do not. "Inline" means they are part of the current line.

What is the use of SPAN tag give an example?

The span tag is used for the grouping of inline elements & this tag does not make any visual change by itself. span is very similar to the div tag, but div is a block-level tag and span is an inline tag. Example 1: In this example, we simply use span tag with style in HTML.

What is div and SPAN tag?

The <span> element shows the inline portion of a document. The <div> elements show a block-level portion of a document. A div is a block-level element and a span is an inline element. The div should be used to wrap sections of a document, while use spans to wrap small portions of text, images, etc.


2 Answers

Another option is this:

<%= link_to content_tag(:span, 'New car'), {:action => "new"}, :class=>"button" %>

docs

like image 110
ryeguy Avatar answered Nov 01 '22 10:11

ryeguy


Or you could be pro and use named routes/resources + Haml. That would make it look like:

%a{ :href => new_car_path }
  %span New Car

What you have is fine though..

like image 37
Jimmy Baker Avatar answered Nov 01 '22 10:11

Jimmy Baker