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?

1

3 Answers 3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

One up for the difference based on input tag generated. Nice tip.
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

Comments

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 %>

2 Comments

I've tried this but I get the http string as the text on the button. Screen shot of part of the button imgur.com/Xa36NpW
Which version of Rails are you using?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.