Silk
Silk

Reputation: 61

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.

Upvotes: 6

Views: 9973

Answers (6)

TattooedJoey
TattooedJoey

Reputation: 93

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

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

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

Upvotes: 0

jasmo2
jasmo2

Reputation: 525

I am using rails 6 and also worked for me.

Upvotes: 0

Norfeldt
Norfeldt

Reputation: 9678

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

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

Upvotes: 1

Olga
Olga

Reputation: 131

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

Upvotes: 3

timberlake
timberlake

Reputation: 777

Try to run

spring stop

rails generate may not work because spring is already running.

Upvotes: 42

DenisStad
DenisStad

Reputation: 27

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?

Upvotes: -1

Related Questions