Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Generators spew stack traces when no type is provided for attributes

#5461

script/rails generate MyModel name

If you leave out the type of the attribute (i.e. should be name:string or similar in the above example), Rails spews a stack trace and exits. Would be helpful with a descriptive error message.

Reported by Christian Johansen · August 25th, 2010 @ 08:44 PM

State: resolved
Milestone: none
Assigned to: José Valim José Valim
Importance: Low

Activity

  1. Rohit Arondekar
    Rohit Arondekar
    • State changed from new to open
    • Assigned user set to Rohit Arondekar
    • Importance changed from to Low

    Confirmed.

    ~/bugmash/devapp९ script/rails generate model MyModel name
    /home/rohit/projects/rails/activesupport/lib/active_support/whiny_nil.rb:48:in `method_missing': undefined method `to_sym' for nil:NilClass (NoMethodError)
        from /home/rohit/projects/rails/railties/lib/rails/generators/generated_attribute.rb:9:in `initialize'
        from /home/rohit/projects/rails/railties/lib/rails/generators/named_base.rb:92:in `new'
        from /home/rohit/projects/rails/railties/lib/rails/generators/named_base.rb:92:in `block in parse_attributes!'
        from /home/rohit/projects/rails/railties/lib/rails/generators/named_base.rb:90:in `map'
        from /home/rohit/projects/rails/railties/lib/rails/generators/named_base.rb:90:in `parse_attributes!'
        from /home/rohit/projects/rails/railties/lib/rails/generators/named_base.rb:14:in `initialize'
        from /home/rohit/.rvm/gems/ruby-1.9.2-p0@3-dev/gems/thor-0.14.0/lib/thor/group.rb:226:in `new'
        from /home/rohit/.rvm/gems/ruby-1.9.2-p0@3-dev/gems/thor-0.14.0/lib/thor/group.rb:226:in `dispatch'
        from /home/rohit/.rvm/gems/ruby-1.9.2-p0@3-dev/gems/thor-0.14.0/lib/thor/base.rb:389:in `start'
        from /home/rohit/projects/rails/railties/lib/rails/generators.rb:163:in `invoke'
        from /home/rohit/projects/rails/railties/lib/rails/commands/generate.rb:10:in `<top (required)>'
        from /home/rohit/projects/rails/activesupport/lib/active_support/dependencies.rb:239:in `require'
        from /home/rohit/projects/rails/activesupport/lib/active_support/dependencies.rb:239:in `block in require'
        from /home/rohit/projects/rails/activesupport/lib/active_support/dependencies.rb:225:in `block in load_dependency'
        from /home/rohit/projects/rails/activesupport/lib/active_support/dependencies.rb:591:in `new_constants_in'
        from /home/rohit/projects/rails/activesupport/lib/active_support/dependencies.rb:225:in `load_dependency'
        from /home/rohit/projects/rails/activesupport/lib/active_support/dependencies.rb:239:in `require'
        from /home/rohit/projects/rails/railties/lib/rails/commands.rb:17:in `<top (required)>'
        from script/rails:6:in `require'
        from script/rails:6:in `<main>'
    

    Would certainly be nice if there was an error message stating that the field needs a type.

    Would you be interested in making a patch? This will be helpful: Contributor Guide

    August 26th, 2010 @ 04:08 AM

  2. Rohit Arondekar
    Rohit Arondekar
    • Assigned user changed from Rohit Arondekar to José Valim

    How about this?

    ~/bugmash/error_app९ script/rails g model FooBar foo
    Missing type for attribute 'foo'.
    Example: 'foo:string' where string is the type.
    
    ~/bugmash/error_app९ script/rails g model FooBar title:string count:integer body
    Missing type for attribute 'body'.
    Example: 'body:string' where string is the type.
    

    Since LH ate my patch, here is a gist: https://gist.github.com/4b0028201b5fe613baba

    September 2nd, 2010 @ 11:01 AM

  3. Repository
  4. Repository
  5. Repository
  6. Repository
  7. Repository
  8. Repository