Button_Tag Like Link_To Rails 3

I need use this code:

<%= button_tag :class => "btn btn-primary" do %>
 <%= t('.follow_all')%>
<% end %>

html output:

<button class="btn btn-primary" name="button" type="submit">
 Follow all
</button>

if it's possible, How can I use this button like a link, something like:

<%= button_tag new_user_registration_path, :class => "btn btn-primary" do %>
     <%= t('.follow_all')%>
    <% end %>

I need use button_tag helper. I can not use link_to helper, or instead, if it's possible, How can I send params from button without use a form?

3 Answers

What about this:

<%= button_tag(:type => 'button') do %>
  <% link_to t('.follow_all'), new_user_registration_path %>
<% end %>
4

Use button_to:

7

Try this:

<%= button_tag onclick: "location.href='{new_user_registration_path}'",
  type: :button, class: "btn btn-primary" do %>
  <%= t('.follow_all')%>
<% end %>

Your Answer

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

Marcus Vance

Marcus Vance

Cybersecurity & Digital Privacy Researcher

Marcus Vance is a cybersecurity auditor and technology writer dedicated to educating the public about online safety, data privacy regulations, enterprise security, and emerging cyber threats.

Share this article
Twitter Facebook Pinterest