This project is archived and is in readonly mode.

#4981 ✓wontfix
Jonas Nielsen

Generator allows stupid errors

Reported by Jonas Nielsen | June 26th, 2010 @ 09:17 AM

The generators allows for stupid errors like:
$ rails g nifty:scaffold title:string content:text rating:integer user_id:integer

I was distracted while writing this, and didn't realize that I forgot to name the scaffold. The generator did not have any problems with this:

create app/models/title:string.rb

  create  test/unit/title:string_test.rb
  create  test/fixtures/title:strings.yml
  create  db/migrate/20100626080439_create_title:strings.rb
  create  app/controllers/title:strings_controller.rb
  create  app/helpers/title:strings_helper.rb
  create  app/views/title:strings/index.html.erb
  create  app/views/title:strings/show.html.erb
  create  app/views/title:strings/new.html.erb
  create  app/views/title:strings/edit.html.erb
  create  app/views/title:strings/_form.html.erb
   route  resources :"title:strings"
  create  test/functional/title:strings_controller_test.rb

Unfortunately the typo error was harder to revert than I expected:

$ rails destroy scaffold title:string /Users/Jonas/.rvm/gems/ruby-1.9.1-p378/gems/actionpack-3.0.0.beta4/lib/action_dispatch/routing/route_set.rb:146:in module_eval': /Users/Jonas/.rvm/gems/ruby-1.9.1-p378/gems/actionpack-3.0.0.beta4/lib/action_dispatch/routing/route_set.rb:147: syntax error, unexpected ':', expecting ';' or '\n' (SyntaxError) ... def hash_for_title:strings_url(options = nil) ... ... ^ /Users/Jonas/.rvm/gems/ruby-1.9.1-p378/gems/actionpack-3.0.0.beta4/lib/action_dispatch/routing/route_set.rb:149: syntax error, unexpected keyword_end, expecting $end

          end                             ...
             ^
from /Users/Jonas/.rvm/gems/ruby-1.9.1-p378/gems/actionpack-3.0.0.beta4/lib/action_dispatch/routing/route_set.rb:146:in `define_hash_access'
from /Users/Jonas/.rvm/gems/ruby-1.9.1-p378/gems/actionpack-3.0.0.beta4/lib/action_dispatch/routing/route_set.rb:137:in `block in define_named_route_methods'
from /Users/Jonas/.rvm/gems/ruby-1.9.1-p378/gems/actionpack-3.0.0.beta4/lib/action_dispatch/routing/route_set.rb:135:in `each'
from /Users/Jonas/.rvm/gems/ruby-1.9.1-p378/gems/actionpack-3.0.0.beta4/lib/action_dispatch/routing/route_set.rb:135:in `define_named_route_methods'
from /Users/Jonas/.rvm/gems/ruby-1.9.1-p378/gems/actionpack-3.0.0.beta4/lib/action_dispatch/routing/route_set.rb:86:in `add'
from /Users/Jonas/.rvm/gems/ruby-1.9.1-p378/gems/actionpack-3.0.0.beta4/lib/action_dispatch/routing/route_set.rb:282:in `add_route'
from /Users/Jonas/.rvm/gems/ruby-1.9.1-p378/gems/actionpack-3.0.0.beta4/lib/action_dispatch/routing/mapper.rb:212:in `match'
from /Users/Jonas/.rvm/gems/ruby-1.9.1-p378/gems/actionpack-3.0.0.beta4/lib/action_dispatch/routing/mapper.rb:369:in `match'
from /Users/Jonas/.rvm/gems/ruby-1.9.1-p378/gems/actionpack-3.0.0.beta4/lib/action_dispatch/routing/mapper.rb:741:in `match'
from /Users/Jonas/.rvm/gems/ruby-1.9.1-p378/gems/actionpack-3.0.0.beta4/lib/action_dispatch/routing/mapper.rb:711:in `match'
from /Users/Jonas/.rvm/gems/ruby-1.9.1-p378/gems/actionpack-3.0.0.beta4/lib/action_dispatch/routing/mapper.rb:287:in `map_method'
from /Users/Jonas/.rvm/gems/ruby-1.9.1-p378/gems/actionpack-3.0.0.beta4/lib/action_dispatch/routing/mapper.rb:239:in `get'
from /Users/Jonas/.rvm/gems/ruby-1.9.1-p378/gems/actionpack-3.0.0.beta4/lib/action_dispatch/routing/mapper.rb:612:in `block (4 levels) in resources'
from /Users/Jonas/.rvm/gems/ruby-1.9.1-p378/gems/actionpack-3.0.0.beta4/lib/action_dispatch/routing/mapper.rb:329:in `scope'
from /Users/Jonas/.rvm/gems/ruby-1.9.1-p378/gems/actionpack-3.0.0.beta4/lib/action_dispatch/routing/mapper.rb:611:in `block (3 levels) in resources'
from /Users/Jonas/.rvm/gems/ruby-1.9.1-p378/gems/actionpack-3.0.0.beta4/lib/action_dispatch/routing/mapper.rb:814:in `with_scope_level'
from /Users/Jonas/.rvm/gems/ruby-1.9.1-p378/gems/actionpack-3.0.0.beta4/lib/action_dispatch/routing/mapper.rb:610:in `block (2 levels) in resources'
from /Users/Jonas/.rvm/gems/ruby-1.9.1-p378/gems/actionpack-3.0.0.beta4/lib/action_dispatch/routing/mapper.rb:814:in `with_scope_level'
from /Users/Jonas/.rvm/gems/ruby-1.9.1-p378/gems/actionpack-3.0.0.beta4/lib/action_dispatch/routing/mapper.rb:607:in `block in resources'
from /Users/Jonas/.rvm/gems/ruby-1.9.1-p378/gems/actionpack-3.0.0.beta4/lib/action_dispatch/routing/mapper.rb:329:in `scope'
from /Users/Jonas/.rvm/gems/ruby-1.9.1-p378/gems/actionpack-3.0.0.beta4/lib/action_dispatch/routing/mapper.rb:606:in `resources'
from /Users/Jonas/RailsProjects/betterspeakers/config/routes.rb:2:in `block in <top (required)>'
from /Users/Jonas/.rvm/gems/ruby-1.9.1-p378/gems/actionpack-3.0.0.beta4/lib/action_dispatch/routing/route_set.rb:213:in `instance_exec'
from /Users/Jonas/.rvm/gems/ruby-1.9.1-p378/gems/actionpack-3.0.0.beta4/lib/action_dispatch/routing/route_set.rb:213:in `draw'
from /Users/Jonas/RailsProjects/betterspeakers/config/routes.rb:1:in `<top (required)>'
from /Users/Jonas/.rvm/gems/ruby-1.9.1-p378/gems/activesupport-3.0.0.beta4/lib/active_support/dependencies.rb:208:in `load'
from /Users/Jonas/.rvm/gems/ruby-1.9.1-p378/gems/activesupport-3.0.0.beta4/lib/active_support/dependencies.rb:208:in `block in load'
from /Users/Jonas/.rvm/gems/ruby-1.9.1-p378/gems/activesupport-3.0.0.beta4/lib/active_support/dependencies.rb:198:in `block in load_dependency'
from /Users/Jonas/.rvm/gems/ruby-1.9.1-p378/gems/activesupport-3.0.0.beta4/lib/active_support/dependencies.rb:554:in `new_constants_in'
from /Users/Jonas/.rvm/gems/ruby-1.9.1-p378/gems/activesupport-3.0.0.beta4/lib/active_support/dependencies.rb:198:in `load_dependency'
from /Users/Jonas/.rvm/gems/ruby-1.9.1-p378/gems/activesupport-3.0.0.beta4/lib/active_support/dependencies.rb:208:in `load'
from /Users/Jonas/.rvm/gems/ruby-1.9.1-p378/gems/railties-3.0.0.beta4/lib/rails/application/routes_reloader.rb:29:in `block in reload!'
from /Users/Jonas/.rvm/gems/ruby-1.9.1-p378/gems/railties-3.0.0.beta4/lib/rails/application/routes_reloader.rb:29:in `each'
from /Users/Jonas/.rvm/gems/ruby-1.9.1-p378/gems/railties-3.0.0.beta4/lib/rails/application/routes_reloader.rb:29:in `reload!'
from /Users/Jonas/.rvm/gems/ruby-1.9.1-p378/gems/railties-3.0.0.beta4/lib/rails/application/routes_reloader.rb:41:in `reload_if_changed'
from /Users/Jonas/.rvm/gems/ruby-1.9.1-p378/gems/actionpack-3.0.0.beta4/lib/action_dispatch/railtie.rb:13:in `block (2 levels) in <class:Railtie>'
from /Users/Jonas/.rvm/gems/ruby-1.9.1-p378/gems/activesupport-3.0.0.beta4/lib/active_support/callbacks.rb:418:in `_run_prepare_callbacks'
from /Users/Jonas/.rvm/gems/ruby-1.9.1-p378/gems/activesupport-3.0.0.beta4/lib/active_support/callbacks.rb:88:in `run_callbacks'
from /Users/Jonas/.rvm/gems/ruby-1.9.1-p378/gems/actionpack-3.0.0.beta4/lib/action_dispatch/middleware/callbacks.rb:40:in `initialize'
from /Users/Jonas/.rvm/gems/ruby-1.9.1-p378/gems/actionpack-3.0.0.beta4/lib/action_dispatch/middleware/stack.rb:33:in `new'
from /Users/Jonas/.rvm/gems/ruby-1.9.1-p378/gems/actionpack-3.0.0.beta4/lib/action_dispatch/middleware/stack.rb:33:in `build'
from /Users/Jonas/.rvm/gems/ruby-1.9.1-p378/gems/actionpack-3.0.0.beta4/lib/action_dispatch/middleware/stack.rb:80:in `block in build'
from /Users/Jonas/.rvm/gems/ruby-1.9.1-p378/gems/actionpack-3.0.0.beta4/lib/action_dispatch/middleware/stack.rb:80:in `each'
from /Users/Jonas/.rvm/gems/ruby-1.9.1-p378/gems/actionpack-3.0.0.beta4/lib/action_dispatch/middleware/stack.rb:80:in `inject'
from /Users/Jonas/.rvm/gems/ruby-1.9.1-p378/gems/actionpack-3.0.0.beta4/lib/action_dispatch/middleware/stack.rb:80:in `build'
from /Users/Jonas/.rvm/gems/ruby-1.9.1-p378/gems/railties-3.0.0.beta4/lib/rails/application.rb:140:in `app'
from /Users/Jonas/.rvm/gems/ruby-1.9.1-p378/gems/railties-3.0.0.beta4/lib/rails/application/finisher.rb:35:in `block in <module:Finisher>'
from /Users/Jonas/.rvm/gems/ruby-1.9.1-p378/gems/railties-3.0.0.beta4/lib/rails/initializable.rb:25:in `instance_exec'
from /Users/Jonas/.rvm/gems/ruby-1.9.1-p378/gems/railties-3.0.0.beta4/lib/rails/initializable.rb:25:in `run'
from /Users/Jonas/.rvm/gems/ruby-1.9.1-p378/gems/railties-3.0.0.beta4/lib/rails/initializable.rb:55:in `block in run_initializers'
from /Users/Jonas/.rvm/gems/ruby-1.9.1-p378/gems/railties-3.0.0.beta4/lib/rails/initializable.rb:54:in `each'
from /Users/Jonas/.rvm/gems/ruby-1.9.1-p378/gems/railties-3.0.0.beta4/lib/rails/initializable.rb:54:in `run_initializers'
from /Users/Jonas/.rvm/gems/ruby-1.9.1-p378/gems/railties-3.0.0.beta4/lib/rails/application.rb:119:in `initialize!'
from /Users/Jonas/.rvm/gems/ruby-1.9.1-p378/gems/railties-3.0.0.beta4/lib/rails/application.rb:81:in `method_missing'
from /Users/Jonas/RailsProjects/betterspeakers/config/environment.rb:5:in `<top (required)>'
from /Users/Jonas/.rvm/gems/ruby-1.9.1-p378/gems/railties-3.0.0.beta4/lib/rails/application.rb:94:in `require'
from /Users/Jonas/.rvm/gems/ruby-1.9.1-p378/gems/railties-3.0.0.beta4/lib/rails/application.rb:94:in `require_environment!'
from /Users/Jonas/.rvm/gems/ruby-1.9.1-p378/gems/railties-3.0.0.beta4/lib/rails/application.rb:81:in `method_missing'
from /Users/Jonas/.rvm/gems/ruby-1.9.1-p378/gems/railties-3.0.0.beta4/lib/rails/commands.rb:16:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'

I'm no expert and the error is pretty dumb, but I'm sure other people eventually will do the same.

Oh, and I'm using Ryan's Nifty Generators http://github.com/ryanb/nifty-generators as well as psynix Rails 3 HAML Scaffold Generator http://github.com/mbleigh/haml-rails

Comments and changes to this ticket

  • Rob Zolkos

    Rob Zolkos October 14th, 2010 @ 03:04 PM

    Rails built-in scaffold generator raieses an exception and won't run if using the same parameters as you tried with nifty_generators.

    The rails framework shouldn't be responsible for catching errors on parameters to 3rd party generators.

    I recommend adding this as an issue to Ryans github repo.

  • Rohit Arondekar

    Rohit Arondekar October 14th, 2010 @ 03:12 PM

    • State changed from “new” to “wontfix”
    • Importance changed from “” to “Low”

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Pages