简体   繁体   中英

Ruby on Rails : rails generate controller does not work

I am new to ruby and rails and I am having a problem with generating controllers.

Some context :

$ rails -v
Rails 4.1.1

App is created correctly :

$ rails new test_app
      create
      create  README.rdoc
      create  Rakefile
      create  config.ru
      create  .gitignore
      create  Gemfile
      create  app
[...]
Your bundle is complete!
Use `bundle show [gemname]` to see where a bundled gem is installed.
         run  bundle exec spring binstub --all
* bin/rake: spring inserted
* bin/rails: spring inserted

Server runs fine :

$ rails server
=> Booting WEBrick
=> Rails 4.1.1 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Notice: server is listening on all interfaces (0.0.0.0). Consider using 127.0.0.1 (--binding option)
=> Ctrl-C to shutdown server
[2014-06-07 11:12:20] INFO  WEBrick 1.3.1
[2014-06-07 11:12:20] INFO  ruby 1.9.3 (2014-02-24) [x86_64-cygwin]
[2014-06-07 11:12:20] INFO  WEBrick::HTTPServer#start: pid=3340 port=3000

I can browse the default page, but then when I try to go to the next step, it's failing :

$ rails generate controller welcome index

Nothing happens and the files are not generated. There is not output at all so I don't know where I should look to fix the issue.

I already tried creating a fresh new app and reinstalling rails, but this doesn't help.

Try to run

spring stop

rails generate may not work because spring is already running.

I had the same problem on my Windows machine while trying to run rails generate controller Users new .

First, make sure your spring is not running. Stop it with spring stop

If it did not help THEN:

  1. Go to your Gemfile and comment out next two lines : gem 'spring' and gem 'spring-watcher-listen', '~> 2.0.0'
  2. In your terminal, run: bundle update

I ran spring stop and it said that it was not running.

Then I did a bundle install and now it worked..

我正在使用 rails 6 并且也为我工作。

Make sure you are in the correct folder and not the environment, eg ~/environment/railsproject .

I got the error and I had forgotten to cd railsproject .

The 'spring' and 'spring-watcher-listen' gems are still installed.

I had the same problem. When I aborted with ctl-c, I got:

/usr/local/rvm/gems/ruby-2.1.0/gems/spring-1.1.3/lib/spring/client/run.rb:54:in `gets': Interrupt
from /usr/local/rvm/gems/ruby-2.1.0/gems/spring-1.1.3/lib/spring/client/run.rb:54:in `verify_server_version'
from /usr/local/rvm/gems/ruby-2.1.0/gems/spring-1.1.3/lib/spring/client/run.rb:25:in `call'
from /usr/local/rvm/gems/ruby-2.1.0/gems/spring-1.1.3/lib/spring/client/command.rb:7:in `call'
from /usr/local/rvm/gems/ruby-2.1.0/gems/spring-1.1.3/lib/spring/client/rails.rb:23:in `call'
from /usr/local/rvm/gems/ruby-2.1.0/gems/spring-1.1.3/lib/spring/client/command.rb:7:in `call'
from /usr/local/rvm/gems/ruby-2.1.0/gems/spring-1.1.3/lib/spring/client.rb:26:in `run'
from /usr/local/rvm/gems/ruby-2.1.0/gems/spring-1.1.3/bin/spring:48:in `<top (required)>'
from /usr/local/rvm/gems/ruby-2.1.0/gems/spring-1.1.3/lib/spring/binstub.rb:11:in `load'
from /usr/local/rvm/gems/ruby-2.1.0/gems/spring-1.1.3/lib/spring/binstub.rb:11:in `<top (required)>'
from /usr/local/rvm/rubies/ruby-2.1.0/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /usr/local/rvm/rubies/ruby-2.1.0/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /usr/share/yapo/bin/spring:16:in `<top (required)>'
from bin/rails:3:in `load'
from bin/rails:3:in `<main>'

So my guess as that the problem was somewhere in spring. I commented the line with spring in the Gemfile, ran bundle update and voila. Hope that works for you, too.

Maybe someone with a little bit more experience with ruby knows wether this is some problem in my/our configuration, or a bug?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM