Reputation: 90
How does Ruby on Rails auto generate the forms input? I've come across the following code and have no idea how the HTML below is being rendered.
<%= f.input :first_name %>
Renders:
<div class="input string required"><label for="user_first_name" class="string required"><abbr title="required">*</abbr> First name</label><input type="text" value="Paul" size="30" required="required" name="user[first_name]" maxlength="255" id="user_first_name" class="string required"></div>
Upvotes: 2
Views: 7622
Reputation: 29599
In addition to what Chris said, the code f.input
probably comes from either formtastic or simple_form. They're gems used to output a preset template using minimal code so you might want to check those.
Upvotes: 1
Reputation: 8247
The HTML is generated by the Rails form helpers. Rails gives you a bunch of methods to make it easier to generate form markup so you don't have to worry about naming and typing out all of the attributes every time. Checkout that link to the docs to get more familiar.
Upvotes: 4