Skip to content
Browse files

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. :-)


    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)
  • Loading branch information...
1 parent d9b873c commit 263764d13a9cd4eae60d1fa9e50af57f506f3dd4 @BMorearty BMorearty committed Sep 23, 2012
2 railties/lib/rails/generators/rails/scaffold_controller/templates/controller.rb
@@ -94,7 +94,7 @@ def <%= "#{singular_table_name}_params" %>
<%- if attributes.empty? -%>
params[<%= ":#{singular_table_name}" %>]
<%- else -%>
- params.require(<%= ":#{singular_table_name}" %>).permit(<%= {|a| ":#{}" }.sort.join(', ') %>)
+ params.require(<%= ":#{singular_table_name}" %>).permit(<%= {|a| ":#{}" }.join(', ') %>)
<%- end -%>

0 comments on commit 263764d

Please sign in to comment.
Something went wrong with that request. Please try again.