gonzalo-bulnes/chilean_cities

Form helpers expectations description

Closed this issue · 1 comments

In order to keep focus on valuable features, the form helpers which are expected to be available for forms building should be defined and described here, or in the README.

Proposal: Polymorphic address association

Given chilean_cities is a Rails engine, it could provide an Address model with a polymorphic belongs_to :addressed, polymorphic: true.

The simpler Address attributes set able to handle any address in Chile seems to be:

- address line 1 (String)
- address line 2 (String)
- city (association, ChileanCities::Comuna)

The form related to that model requires at least a <select> tag to set the association. Since there are 350+ cities, that's not very user-friendly. In a first time, it could be replaced by a Bootstrap typeahead. (Other select latyouts such as ordering the cities by region could be considered later.)

The typical usage of the gem would become:

  1. generate the cities seed and run migrations
  2. add has_one work_address, as: :addressed to your models
  3. add the address(es) to your models forms (should be possible with something like):
form_for :my_model_instance,  do |f|
  # ...
  f.fields_for :work_address do |work_address_form| do
    work_address_form.input :line_one
    work_address_form.input :line_two
    work_address_form.city, collection: ChileanCities::Comuna.all
  end
  # ...
end