Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

scaffold/model/migration generators not correctly generate decimal with precision scale shorthand #4602

Closed
joneslee85 opened this Issue · 5 comments

6 participants

Trung Lê Chris Gunther Rafael Mendonça França nmagedman Liang Chen José Valim
Trung Lê

rails g scaffold Post price:decimal{7,2} generates:

    t.decimal7 :price
    t.decimal2 :price 

which is so wrong.

José Valim josevalim closed this in ede01ce
Jeremy Walker iHiD referenced this issue from a commit in iHiD/rails
José Valim josevalim Support decimal{1,2} and decimal{1-2} and decimal{1.2} so it works fi…
…ne with bash, zsh, etc, closes #4602

Conflicts:

	railties/test/generators/migration_generator_test.rb
1f9d6a0
Trung Lê

The {1.2} and {1-2} works however the {1,2} still produce wrong migration. Please re-open the ticket.

Chris Gunther

I'm on 3.2.1, ZSH and {1,2} doesn't work for me either. Switching to {1-2} did work though.

Rafael Mendonça França
Owner

Hey @joneslee85 and @cgunther the {1.2} and {1-2} as added to users with shell that expand the {1,2} syntax. So if {1,2} doesn't work to you please use {1.2} or {1-2} syntax.

nmagedman

Just to clarify the issue for the benefit of anyone who googles their way here:

The Rails generator wasn't broken. The documentation just failed to take into account that curly braces are metacharacters in Bash (as well as other shells) and need to be escaped.

Run

$ echo rails g scaffold Post price:decimal{7,2}

and you'll see that it expands to

rails g scaffold Post price:decimal7 price:decimal2

The generator isn't smart enough to detect that you defined two columns named price. Nor does it catch that there are no such datatypes as decimal7 or decimal2.

The proper thing to do is to escape the braces with either quotes or backslashes.

Alternatively, you can use an alternate form that Jose Valim added last month.
Instead of a comma, use a dot or dash. Bash does not expand those forms:

$ echo price:decimal{7.2} price:decimal{7-2}
price:decimal{7.2} price:decimal{7-2}
Liang Chen

{1,2} doesn't work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.