ruby-on-rails-4link-tourlhelperbutton-to

Use button_to for external link via GET


As a test, I used both link_to and button_to, but only the former is working. With the latter, it looks like the params are just not passed, because I get an error from Facebook saying there's no client_id when there certainly is in the URL.

link_to code:

<%= link_to "test", @auth_url %>

<!-- rendered HTML -->
<a href="https://www.facebook.com/v2.0/dialog/oauth?client_id=XYZ...">test</a>

button_to code:

<%= button_to @auth_url, method: :get, class: "btn btn-block btn-lg btn-social btn-facebook", style: "color:white" do %>
   <i class="fa fa-facebook horiz"></i> Invite me with Facebook
<% end %>

<!-- rendered HTML -->
<form action="https://www.facebook.com/v2.0/dialog/oauth?client_id=XYZ..." class="button_to" method="get">
  <div>
    <button class="btn btn-block btn-lg btn-social btn-facebook" style="color:white" type="submit">
      <i class="fa fa-facebook horiz"></i> Invite me with Facebook
    </button>
  </div>
</form>

I would like to use the button_to because I want a button... but I can style the link as such if there's no way of getting this to work.

Thanks!


Solution

  • In this case, there's so many issues I discovered with styling a button across different browsers, that I ended up just using Javascript like so:

    $("#inviteme3").click(function() {
      var link_string = '<%= @auth_url %>';
      var decoded = link_string.replace(/&amp;/g, '&');
      location.href = decoded
      return false;
    });