upmin / upmin-admin-ruby

Framework for creating powerful admin backends with minimal effort in Ruby on Rails.
MIT License
755 stars 66 forks source link

Upmin::Attribute type for money attributes #155

Closed tfe closed 9 years ago

tfe commented 9 years ago

It would be nice to have a specialized attribute type for the common Rails practice of having a foo_in_cents or foo_cents column. Ideally it would:

  1. Remove the "cents" from the display label name
  2. Display the amount divided by 100 and with the currency symbol, i.e. number_to_currency
  3. Allow editing by reversing the currency symbol/division by 100 when saving an edited field.

Since 3 is much more complicated than 1 and 2, I propose first releasing a "money_cents" partial which does only 1 and 2, presenting the attribute as an un-editable field.

mbrookes commented 9 years ago

I understand the concept, but I'm not sure that this column naming is common practice - there are a handful of ruby projects on GitHub with _cents in the code, and not all of those are Rails related. Also, many currency don't use cents as the smallest unit, so I18n is a bit of a problem. Is there a way to make this more column name and currency agnostic?

tfe commented 9 years ago

Fair point; maybe it's best left to the app owner to customize for their use.

That being said, it might be a nice optional widget/partial to offer along the lines of the current progress_bar. Locals could allow for a custom divisor, gsub string, and options to pass to number_to_currency.

If you'd be interested in merging the associated PR with those modifications, I can make them.

mbrookes commented 9 years ago

Sounds reasonable. Do you plan to tackle editability at a later stage? - turning a read-write field into a read-only one just for display purposes strikes me as a slightly negative trade-off for an admin interface. (Appreciate it will be an optional partial.)