Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use a link_to to generate a link with a span inside?

Tags:

I am basically trying to get this result:

        <a href="#" class="button small-button green-button">
            Log in
            <span class="button-right"></span>
        </a>

But I don't know how to do this with a link_to in rails 3 ?

like image 590
Alex Avatar asked Jan 29 '11 16:01

Alex


People also ask

What is link_ to in Rails?

link_to is a Rails built in helper that helps generate an anchor tag.


2 Answers

You can use the block form of link_to for that:

<%= link_to "#", :class => "button small-button green-button" do %>
  Log in
  <span class="button-right"></span>
<% end %>
like image 195
Paige Ruten Avatar answered Sep 19 '22 11:09

Paige Ruten


The simplest way to do it is by using html_safe or raw functions

<%= link_to 'Log In<span class="button-right"></span>'.html_safe %>

or using raw function (recommended)

<%= link_to raw('Log In<span class="button-right"></span>') %>

Simple as it can get !!

Don’t use html_safe method unless you’re sure your string isn’t nil. Instead use the raw() method, which wont raise an exception on nil.

like image 22
Nikhil Nanjappa Avatar answered Sep 19 '22 11:09

Nikhil Nanjappa