990 Simple Form [2d]

Updated . Posted . Visible to the public.

In some projects we use Simple Form Show archive.org snapshot to write boring forms more quickly.

Important

Work on this lesson in builder mode.

Learning goals

  • You can explain what Simple Form does for a form, where it pays off, and where plain form helpers are the better choice.
  • You can configure Simple Form's generated HTML to match a project's markup, e.g. with its Bootstrap wrapper configuration.
  • You can write forms with Simple Form's input types and options.
  • You can extend Simple Form with a custom input type.

Resources

Read what's new to you, skim what's familiar, skip what you already master. Stop when you can meet the learning goals.

Your agent can also generate an overview, a tutorial or an explanation for anything here, tailored to what you already know. Just ask.

Exercises

Use Simple Form

Tip

Make sure that the Simple Form Bootstrap initializer is configured for the correct Bootstrap version Show archive.org snapshot . Version 5.1 of the gem currently gives you an outdated configuration for Bootstrap 4.

Rewrite two boring forms in MovieDB so they use Simple Form.

Expect some pain to initially configure Simple Form to use the HTML structure of your MovieDB. After that your forms should be much shorter than before.

Extend Simple Form

Extend your Simple Form integration with a new input type :money that may be used like this:

= form.input :amount, as: :money

Money inputs differ from regular numeric inputs:

  • After the input there is an Euro symbol ("€") (it's not part of the input value)
  • The input value should always be rounded to two digits precision.
    • E.g. when the money amount is 2, the value should display as 2.00. When the amount is 3.5 it should display as 3.50.
    • The rounding only needs to be applied when Rails renders the input. It does not need to be applied while the user is typing in a new value.
Profile picture of Henning Koch
Henning Koch
Last edit
Michael Leimstädtner
License
Source code in this card is licensed under the MIT License.
Posted by Henning Koch to makandra Curriculum (2018-12-12 17:04)