Skip to content

SimpleForm

JP Barbosa edited this page Jul 23, 2015 · 2 revisions

SimpleForm

Add SimpleForm gem and restart server
echo "gem 'simple_form'" >> Gemfile
bundle install
rails s
Simplify authors form
nano app/views/authors/_form.html.erb
<%= simple_form_for(@author) do |f| %>
  <%= f.input :name %>
  <%= f.input :email %>
  <%= f.button :submit %>
<% end %>
Simplify articles form
nano app/views/articles/_form.html.erb
<%= simple_form_for(@article) do |f| %>
  <%= f.input :title %>
  <%= f.input :content %>
  <%= f.association :author %>
  <%= f.button :submit %>
<% end %>
Open forms in the browser to check
open http://localhost:3000/articles/new
open http://localhost:3000/authors/new
Add SimpleForm to Git
git add .
git commit -m "Add SimpleForm"
Next step: Bootstrap