HTML / ERB - Standard-Button?

Ismoh picture Ismoh · Apr 5, 2014 · Viewed 9.4k times · Source

It's just a simple question, but I don't know how it's called:

In the picture you can see 2Buttons: screenshot

I want the user to just type in the email and password and accept it by pressing return. Is there a opportunity to set this up ?

I know that there is a option in C#, but I forgot how it's called. (Standard-Button?)

I am not able to post a picture.. (You need at least 10 reputation to post images..)

so: There are 2 input-texts and 2buttons (Login-Form / Register) eMail - Password - Login-Btn and or-Register-btn. The user types in his email and password. After that he press "return" to accept and he is logged in. How is the options called that the login-btn is the ... first button to choose by pressing "return"?

I hope you can understand, but I guess it is clear.


That's what I am using:

  • Ruby on Rails 4
  • HTML
  • HTML.ERB
  • Bootstrap 3

Thanks.

Answer

Richard Peck picture Richard Peck · Apr 6, 2014

You may have an answer, but to help you understand it, you need to remember Rails renders everything as HTML on the browser-side; so every element you want to display has to be some sort of HTML object

If you want to show a button in Rails, there are a number of ways to do it:


button_to

This creates a simple form which points to a URL. The form has a button element inside, making it look like a pure HTML button to the user:

<%= button_to "New", action: "new" %>
# => "<form method="post" action="/controller/new" class="button_to">
#      <div><input value="New" type="submit" /></div>
#    </form>"

f.submit

For your specific issue, I think you'll benefit from f.submit, which basically adds a submit button to your form:

<%= form_for @var do |f| %>
    <%= f.submit "Register" %>
<% end %>

If you'd like to style this, you'll be able to apply classes to the button directly:

<%= f.submit "Text", class: "class" %>