calebhearth / formulaic

Simplify form filling with Capybara
MIT License
552 stars 29 forks source link

Reliance on human_attribute_name does not work with plural model classes #65

Closed derekprior closed 2 years ago

derekprior commented 7 years ago

I have an ActiveModel class named Credentials with encapsulates an email and password form. I define the following translations:

---
en:
  activemodel:
    attributes:
      credentials:
        email: Email Address
        password: Password

However, when I call fill_form(:credentials, { email: 'foo@bar.com', password: 'password' }, I get an InputNotFound error. Formulaic first tries to use simple form translations to find the input. Failing that, it tries to get at human attribute name by classifying the model name passed to fill_form. Unfortunately, classify uses the inflector to singularize the input.

I don't know if there's a great solution to this. I can't think of a scenario where the singularization would be useful for formulaic, but I also think reimplementing classify might be more trouble than its worth here as well.

For now, I can work around this by duplicating the translations as simple_form label translations, but this is also not an ideal solution.

derekprior commented 7 years ago

adding inflect.uncountable 'credentials' to my inflections also fixes this and is likely a fine solution for this (even though its a lie). If you don't have a good idea for fixing this without the inflector, then feel free to close.