1

I want to use an icon on a Twitter intent button.

<%= button_to "Share on Twitter", "https://twitter.com/intent/tweet?text=#{@twitter_message}", :class => "btn" %>

Is it possible?

There are 2 other buttons on the page using button_tag helpers and I can insert the icons into those buttons. Should I convert the button_to into a button_tag and if so how?

grabury
  • 4,797
  • 14
  • 67
  • 125
  • [There's a lengthy discussion on adding image into `input` tag](http://stackoverflow.com/questions/195632/how-to-change-an-input-button-image-using-css) – Jason Kim Aug 06 '13 at 09:17

3 Answers3

3

According to the button_to documentation, it generates an input tag:

<%= button_to "New", action: "new" %>

<form method="post" action="/controller/new" class="button_to">
   <div><input value="New" type="submit" /></div>
</form>"

So you should use link_to instead, with a button class, like:

<%= link_to "Share on Twitter", "https://twitter.com/intent/tweet?text=#{@twitter_message}", :class => "btn icon-edit" %>

I've done this using twitter bootstrap.

Paulo Fidalgo
  • 21,709
  • 7
  • 99
  • 115
1

Why to not use link_to instead, as more suitable for your case.

link_to 'http://tweeter.com/bla-bla', class: 'btn' do
    # Your text and icon
end
hawk
  • 5,409
  • 2
  • 23
  • 29
0

This should work:

<%= button_to "https://twitter.com/intent/tweet?text=#{@twitter_message}", :class => "btn" do %>
   <i class="icon-something"></i>Share on Twitter
<% end %>
Ju Liu
  • 3,939
  • 13
  • 18