Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates the form class names to use rails pattern #2

Conversation

CaiqueMitsuoka
Copy link

The problem

When creating the form field with the Attachy helper, things worked fine for classes with single word names, like User, with the #downcase method. But when the class had a composed name like AdminUser the result would be adminuser since #downcase only replaces uppercase chars with the downcased version.

Before example:

## View code
## ...
<%= f.attachy :avatar %>
<%= f.text_field :name %>

## Controller params inspect
params
# Output: <ActionController::Parameters {
#   "adminuser" => {
#     "avatar" => [...]
#   },
#   "admin_user"=> {
#     "name" => "Foo Bar"
#    }
# } permitted: false>

The solution

Rails uses the #underscore method to generate the downcased underscore separed class names to generate form. So when composed words classes use the attachy helper the field would come in a different form data.

After example

## View code
## ...
<%= f.attachy :avatar %>
<%= f.text_field :name %>

## Controller params inspect
params
# Output: <ActionController::Parameters {
#   "admin_user"=> {
#     "name" => "Foo Bar"
#     "avatar" => [...]
#    }
# } permitted: false>

@CaiqueMitsuoka CaiqueMitsuoka changed the title Updates the form class name to use rails pattern Updates the form class names to use rails pattern Apr 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant