PecanProject / bety

Web-interface to the Biofuel Ecophysiological Traits and Yields Database (used by PEcAn and TERRA REF)
https://www.betydb.org
BSD 3-Clause "New" or "Revised" License
16 stars 38 forks source link

Editing an existing site with a non-standard country name will change the value to the empty string. #513

Open gsrohde opened 7 years ago

gsrohde commented 7 years ago

The country field in the edit form will not be pre-populated if the country stored in the database does not match one of a given set of country values. Then, if the Update button is pressed, the country takes the (blank) value in the form.

gsrohde commented 5 years ago

Details:

When a site is created in the BETYdb Rails app, a country can be chosen from a predetermined list of country names in a drop-down widget. The default, if no choice is made, is blank (the empty string). The choices appear as spelled-out country names, but what is stored in the database is the corresponding two-letter country code. The country names and codes seem to largely match this table given in the Wikipedia article ISO 3166-1 alpha-2 except that in the drop-down, the names are shown in all caps—for what seems to me no good reason—rather than in title case.

Note that on the view page and in the index page, unlike in the edit page, what appears as the "country" is exactly what is stored in the database. If the country was entered via the Rails app, this will be the two-letter abbreviation rather than the full country name. Except for common familiar country codes like "US", "IT", "FR", and "GB", most users will probably have to look up these codes to decipher them. In some cases, looking at the city name may help: most users will be able to glean that city: Buenos Aires, country: AR refers to Buenos Aires, Argentina and not Buenos Aires, Armenia. (Or maybe not: there is a site listed in the EBI database with city: Buenos Aires, country BR.)

Later, when a site is edited, the edit page displays the chosen country preselected in the drop-down widget. It does this by looking at the stored two-letter code and finding the corresponding country name. But if the country value stored in the database does not match any of the values recognized in the Rails code associated with the drop-down widget, a blank entry for the country is displayed. If the user then saves the update without re-choosing the intended (or some other) country, the empty string is stored in the country column for that site.

Non-standard values presumably appear in the database for one of two reasons: (a) the site was created or update by some means other than using the BETYdb Rails app; (b) the site was created or updated using a previous version of the Rails app that didn't enforce such restrictions on the stored country column value. ((a) seems most likely.)