无法运行Rails控制台,我不确定是什么问题

问题描述 投票:0回答:1

我对Rails并不陌生,对开发总体而言还很陌生。

我正在尝试运行Rails控制台,但收到一堆消息,但我无法确定问题出在哪里。其他rails命令正在运行

我在gemfile中看到了运行spring stop或注释sp​​ring的建议,但都没有用。

我在终端上得到的是:

rails console
/home/lutzcc1/code/lutzcc1/rails-task-manager/config/routes.rb:4:in `block in <main>': undefined local variable or method `new_task' for #<ActionDispatch::Routing::Mapper:0x0000557103736ee0> (NameError)
    from /home/lutzcc1/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/actionpack-6.0.2.2/lib/action_dispatch/routing/route_set.rb:429:in `instance_exec'
    from /home/lutzcc1/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/actionpack-6.0.2.2/lib/action_dispatch/routing/route_set.rb:429:in `eval_block'
    from /home/lutzcc1/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/actionpack-6.0.2.2/lib/action_dispatch/routing/route_set.rb:411:in `draw'
    from /home/lutzcc1/code/lutzcc1/rails-task-manager/config/routes.rb:1:in `<main>'
    from /home/lutzcc1/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:55:in `load'
    from /home/lutzcc1/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:55:in `load'
    from /home/lutzcc1/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/railties-6.0.2.2/lib/rails/application/routes_reloader.rb:41:in `block in load_paths'
    from /home/lutzcc1/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/railties-6.0.2.2/lib/rails/application/routes_reloader.rb:41:in `each'
    from /home/lutzcc1/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/railties-6.0.2.2/lib/rails/application/routes_reloader.rb:41:in `load_paths'
    from /home/lutzcc1/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/railties-6.0.2.2/lib/rails/application/routes_reloader.rb:20:in `reload!'
    from /home/lutzcc1/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/railties-6.0.2.2/lib/rails/application/routes_reloader.rb:30:in `block in updater'
    from /home/lutzcc1/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/activesupport-6.0.2.2/lib/active_support/file_update_checker.rb:83:in `execute'
    from /home/lutzcc1/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/railties-6.0.2.2/lib/rails/application/routes_reloader.rb:10:in `execute'
    from /home/lutzcc1/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/railties-6.0.2.2/lib/rails/application/finisher.rb:184:in `block in <module:Finisher>'
    from /home/lutzcc1/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/railties-6.0.2.2/lib/rails/initializable.rb:32:in `instance_exec'
    from /home/lutzcc1/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/railties-6.0.2.2/lib/rails/initializable.rb:32:in `run'
    from /home/lutzcc1/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/railties-6.0.2.2/lib/rails/initializable.rb:61:in `block in run_initializers'
    from /home/lutzcc1/.rbenv/versions/2.6.6/lib/ruby/2.6.0/tsort.rb:228:in `block in tsort_each'
    from /home/lutzcc1/.rbenv/versions/2.6.6/lib/ruby/2.6.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
    from /home/lutzcc1/.rbenv/versions/2.6.6/lib/ruby/2.6.0/tsort.rb:431:in `each_strongly_connected_component_from'
    from /home/lutzcc1/.rbenv/versions/2.6.6/lib/ruby/2.6.0/tsort.rb:349:in `block in each_strongly_connected_component'
    from /home/lutzcc1/.rbenv/versions/2.6.6/lib/ruby/2.6.0/tsort.rb:347:in `each'
    from /home/lutzcc1/.rbenv/versions/2.6.6/lib/ruby/2.6.0/tsort.rb:347:in `call'
    from /home/lutzcc1/.rbenv/versions/2.6.6/lib/ruby/2.6.0/tsort.rb:347:in `each_strongly_connected_component'
    from /home/lutzcc1/.rbenv/versions/2.6.6/lib/ruby/2.6.0/tsort.rb:226:in `tsort_each'
    from /home/lutzcc1/.rbenv/versions/2.6.6/lib/ruby/2.6.0/tsort.rb:205:in `tsort_each'
    from /home/lutzcc1/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/railties-6.0.2.2/lib/rails/initializable.rb:60:in `run_initializers'
    from /home/lutzcc1/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/railties-6.0.2.2/lib/rails/application.rb:363:in `initialize!'
    from /home/lutzcc1/code/lutzcc1/rails-task-manager/config/environment.rb:5:in `<main>'
    from /home/lutzcc1/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
    from /home/lutzcc1/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
    from /home/lutzcc1/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
    from /home/lutzcc1/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
    from /home/lutzcc1/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
    from /home/lutzcc1/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/zeitwerk-2.3.0/lib/zeitwerk/kernel.rb:23:in `require'
    from /home/lutzcc1/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/activesupport-6.0.2.2/lib/active_support/dependencies.rb:325:in `block in require'
    from /home/lutzcc1/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/activesupport-6.0.2.2/lib/active_support/dependencies.rb:291:in `load_dependency'
    from /home/lutzcc1/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/activesupport-6.0.2.2/lib/active_support/dependencies.rb:325:in `require'
    from /home/lutzcc1/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/spring-2.1.0/lib/spring/application.rb:106:in `preload'
    from /home/lutzcc1/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/spring-2.1.0/lib/spring/application.rb:157:in `serve'
    from /home/lutzcc1/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/spring-2.1.0/lib/spring/application.rb:145:in `block in run'
    from /home/lutzcc1/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/spring-2.1.0/lib/spring/application.rb:139:in `loop'
    from /home/lutzcc1/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/spring-2.1.0/lib/spring/application.rb:139:in `run'
    from /home/lutzcc1/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/spring-2.1.0/lib/spring/application/boot.rb:19:in `<top (required)>'
    from /home/lutzcc1/.rbenv/versions/2.6.6/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    from /home/lutzcc1/.rbenv/versions/2.6.6/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    from -e:1:in `<main>'

这是我的路线文件:

Rails.application.routes.draw do
  get 'tasks', to: 'tasks#index'
  get 'tasks/new', to: 'tasks#new', as: new_task
  post 'tasks', to: 'tasks#create'
  get 'tasks/:id', to: 'tasks#show', as: tasks
  get 'tasks/:id/edit', to: 'task#edit', as: edit_task
  patch 'tasks/:id', to: 'task#update'
  delete 'task/:id', to: 'task#destroy'
end
ruby-on-rails ruby rubygems
1个回答
0
投票

这里是问题:

as: new_task

您可能是想

as: :new_task

这就是为什么Rails抱怨未定义的方法或变量new_task

© www.soinside.com 2019 - 2024. All rights reserved.