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

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

Closed
runlevel5 opened this issue Jan 22, 2012 · 5 comments

Comments

@runlevel5
Copy link
Contributor

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

    t.decimal7 :price
    t.decimal2 :price 

which is so wrong.

iHiD pushed a commit to iHiD/rails that referenced this issue Jan 22, 2012
…ne with bash, zsh, etc, closes rails#4602

Conflicts:

	railties/test/generators/migration_generator_test.rb
@runlevel5
Copy link
Contributor Author

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

@cgunther
Copy link
Contributor

cgunther commented Feb 4, 2012

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

@rafaelfranca
Copy link
Member

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
Copy link

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}

@hinagiku
Copy link

{1,2} doesn't work

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

No branches or pull requests

6 participants