6

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.

21
  • 1
    did you write that command in a separate tab or in the same tab but after closing the server? Commented Jun 7, 2014 at 10:33
  • As I am seeing the $ symbol before the rails gene.. command, I didn't guess about the mistake. But it can be ...... Commented Jun 7, 2014 at 10:36
  • Do you have ActiveRecord enabled? Or maybe you have a custom generator called 'controller' created by accident? Commented Jun 7, 2014 at 10:37
  • @StefanHagen How to check if it is enabled or not ? Commented Jun 7, 2014 at 10:38
  • Yes it is a separate tab in the app folder. The $ is just the cygwin command prompt. I have seen people having a problem with custom generator, but I have no clue how I can see if I have one. (sorry for the half reply, pressing enter sends the reply right away :-/) Commented Jun 7, 2014 at 10:38

6 Answers 6

42

Try to run

spring stop

rails generate may not work because spring is already running.

Sign up to request clarification or add additional context in comments.

2 Comments

My surprise violated the principle of least surprise. I was having a good time following the guide here. I thought I would practice some more by deleting my project directory and start over when bin/rails generate controller welcome index resulted in no output and no file controller generation. That led me to this post. spring stop fixed the issue. Now I have to google spring stop so this will no longer surprise me.
This is the correct answer
3

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

Comments

1

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

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

Comments

0

I am using rails 6 and also worked for me.

Comments

0

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.

Comments

-1

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?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.