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.
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.
<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.
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.
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.
Another option is this:
<%= link_to content_tag(:span, 'New car'), {:action => "new"}, :class=>"button" %>
docs
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..
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With