grabury
grabury

Reputation: 5559

Change rails button_to helper into button_tag helper

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?

Upvotes: 1

Views: 790

Answers (3)

hawk
hawk

Reputation: 5408

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

Upvotes: 1

Paulo Fidalgo
Paulo Fidalgo

Reputation: 22296

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.

Upvotes: 3

Ju Liu
Ju Liu

Reputation: 3999

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

Upvotes: 0

Related Questions