1

Using the this button_to helper:

<%= button_to "Add Beer", "/growlers/create", method: "get" %>

yields the following HTML:

<form action="/growlers/create" class="button_to" method="get">
<div>
<input type="submit" value="Add Beer" />
</div>
</form>

Which is exactly what is supposed to happen. However, as you can see, the HTML element is a <form>. I am wondering how to render this as a <button> for styling purposes (using Foundation).

I found this:

<%= link_to "<button>Add Beer</button>".html_safe, "/growlers/create", method: "get" %>

yields this HTML:

<a data-method="get" href="/growlers/create">
<button>Add Beer</button>
</a>

Which, though a <button>, doesn't seem perfect to me.

I am curious if there are any other solutions/workarounds to this issue.

2 Answers 2

3

If you wrap your button label in the button_to statement:

<%= button_to "/growlers/create", method: "get" do %>
  Add Beer
<% end %>

It will render the wrapped text within a element inside the form. props to apidock: https://apidock.com/rails/ActionView/Helpers/UrlHelper/button_to

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

Comments

2

Are you looking for button_tag?

http://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html#method-i-button_tag

Comments

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.