SimpleForm is meant to streamline the code you write for making a form.
-
Less code!
-
Still looks good!
Remember the blog tutorial from the Ruby on Rails documentation? Let's change it up with SimpleForm. This is the form to create a new blog article:
<%= form_for @article do |f| %>
<p>
<%= f.label :title %><br>
<%= f.text_field :title %>
</p>
<p>
<%= f.label :text %><br>
<%= f.text_area :text %>
</p>
<p>
<%= f.submit %>
</p>
<% end %>
Now here is how you would make the same form with SimpleForm:
<%= simple_form_for(@article, html: {class: '.form-horizontal'}) do |f| %>
<%= f.input :title, placeholder: 'Title' %><br>
<%= f.input :text, placeholder: 'Write an article here' %><br>
<%= f.button :submit %>
<% end %>
There are actually even more ways to simplify your code.
Add it to your Gemfile
Or install the gem
Run bundle install
Run the generator
It creates the files then tells you what to code in the console! Then simply refer to the docs for more.