Rails form view with a send button
-
21-07-2021 - |
Question
I have a form generated by scaffold in my _form.html.erb
<%= form_for @survey do |f| %>
<%= f.label :name %><br />
<%= f.text_field :name %>
<%= f.submit "Send", class: "btn btn-red span3" %>
<% end %>
my submit input produces:
<input class="btn btn-red span3" name="commit" type="submit" value="Send">
I want to produce a button instead a input. Like this:
<button class="btn btn-red span3" name="commit" type="submit">Send</button>
Any tip?
Solution 2
I discovered a simple way
<%= button_tag "Send", class: "btn btn-red span3", name: "commit" %>
produces:
<button class="btn btn-red span3" name="commit" type="submit">Send</button>
OTHER TIPS
<%= content_tag :button, type: :submit, class: "btn btn-red span3" do %>
Send
<% end %>
Produces following HTML
<button class="btn btn-red span3" type="submit">
Send
</button>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow