Removed sorting of attribute names in controller generator. #7740

Merged
merged 2 commits into from Sep 23, 2012

Conversation

Projects
None yet
3 participants
Contributor

BMorearty commented Sep 23, 2012

I believe when people use generators, they typically order the
parameters on the command line in an order that makes sense
to them. Sorting them in the generated code makes the order
seem more arbitrary to humans, even though it's less arbitrary
to computers. :-)

Example:

rails g scaffold Post title:string content:text

The human chose to put title before content. Sorted
attributes in the generated code work but don't match the
human's intent:

params.require(:posts).permit(:content, :title)
Removed sorting of attribute names in controller generator.
I believe when people use generators, they typically order the
parameters on the command line in an order that makes sense
to them.  Sorting them in the generated code  makes the order
seem more arbitrary to humans, even though it's less arbitrary
to computers. :-)

Example:

    rails g scaffold Post title:string content:text

The human chose to put title before content. Sorted
attributes in the generated code work but don't match the
human's intent:

    params.require(:posts).permit(:content, :title)
Contributor

josevalim commented Sep 23, 2012

Yes! Have you run the tests? Do they still pass? You can simply do:

cd railties
TEST_DIR=generators rake test

So you don't have to wait for the whole suit.

Contributor

BMorearty commented Sep 23, 2012

Thanks for the pointer to the right tests to run, @josevalim. I did previously try to run the tests but got a bundler error. Now I have fixed the error (by updating my bundler gem) and I ran the generators tests.

Running now. Taking awhile. I will update you when they are complete.

Contributor

BMorearty commented Sep 23, 2012

Fixed the one test that broke.

All generator tests are green now. 💚

Member

steveklabnik commented Sep 23, 2012

👍

josevalim added a commit that referenced this pull request Sep 23, 2012

Merge pull request #7740 from BMorearty/dont-sort-params
Removed sorting of attribute names in controller generator.

@josevalim josevalim merged commit 09d298e into rails:master Sep 23, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment