simo
simo

Reputation: 24560

"rails generate controller" is not creating a controller

I am trying to run this in the terminal:

rails generate controller welcome index

However, it is not creating a controller. The process finished with exit code 0.

Any ideas?

EDIT

My Environment

RUBYGEMS VERSION: 1.8.10
RUBY VERSION: 1.9.3 (2011-10-30 patchlevel 0) [i686-linux]
INSTALLATION DIRECTORY: /home/sam/.rvm/gems/ruby-1.9.3-p0@myapp
RUBY EXECUTABLE: /home/sam/.rvm/rubies/ruby-1.9.3-p0/bin/ruby
EXECUTABLE DIRECTORY: /home/sam/.rvm/gems/ruby-1.9.3-p0@myapp/bin
RUBYGEMS PLATFORMS:
  ruby
  x86-linux
GEM PATHS:
   /home/sam/.rvm/gems/ruby-1.9.3-p0@myapp
   /home/sam/.rvm/gems/ruby-1.9.3-p0@global
GEM CONFIGURATION:
   :update_sources => true
   :verbose => true
   :benchmark => false
   :backtrace => false
   :bulk_threshold => 1000
REMOTE SOURCES:
   http://rubygems.org/
----------------------
IDE: JetBrains RubyMine 4.0.3, build #RM-117.159
OS: Linux 3.0.0-17-generic[i386]
Java: 1.7.0-b147
RubyMine SDK Environment:
Sdk: RVM: ruby-1.9.3-p0 [myapp]
Sdk Version: ver.1.9.3p0 ( revision 33570) p0
Ruby Interpreter: /home/sam/.rvm/rubies/ruby-1.9.3-p0/bin/ruby
RVM Sdk: yes, gemset:myapp
RVM Home: /home/sam/.rvm
Sdk Language Level: 1.9
Sdk Load Path:
     ~/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1
     ~/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/i686-linux
     ~/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby
     ~/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/vendor_ruby/1.9.1
     ~/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/vendor_ruby/1.9.1/i686-linux
     ~/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/vendor_ruby
     ~/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1
     ~/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/i686-linux
     /opt/RubyMine-4.0.3/rubystubs19

Upvotes: 2

Views: 11277

Answers (3)

Peter Andersson
Peter Andersson

Reputation: 2047

I had run into the same problem. When I ran the command in another Rails-app it worked, it was just in this particular project it didn't!

Turns out the answer was this: I had by accident created my own generator named controller! This can happen if you use the command "rails g generator controller".

A customized controller was then created (you can find it in lib/generators/controller/controller_generator) and when I then used "rails g controller welcome index" it was my own generator that was run, and of course it did nothing!

Somehow I think this mistake should be avoided by having rails (per default at least) stop me from creating a generator by accident! It's stupid I know but it happened to me.

Upvotes: 6

Wout Neirynck
Wout Neirynck

Reputation: 81

I've had the same problem. I discovered it was because I had previously disabled active record. In the config/application.rb, make sure the line:

require "active_record/railtie"

is uncommented. After that it should work (also, make sure you have a valid config/database.yml file).

Upvotes: 8

YogiZoli
YogiZoli

Reputation: 890

Interesting problem. I read all your environment info and seems absolutely ok, you're using RVM, Gemset is in use, Rubymine well, etc.

I'm not sure about the solution but there's couple of ways which I'd give a try so I'm gonna share these.

Maybe your Gemset is in use but was not used when you've tried first. check settings of Ribymine if it see your RVM settings correctly.

Other Rubymine tasks went well without any problem? Server starts correctly?

  1. Try rails generate - if Rails commands work then you must see some basic help info about what you can generate.

  2. Try simply rails g controller Welcome, you can add index method later.

  3. From shell try simply use rails -v to see Rails version and if its in use correctly. Maybe it seemes idiot for first shot, but you may have struggle when you don't set the Gemset as default.

  4. Check /script folder, is there rails.rb in it? Have you modified this file or removed?

  5. Try other rails comments, first try to generate a model for example, then try rake tasks to see what other problems occurs.

Without more error info it's really hard to guess more, tried my best. Maybe these are newbie stuffs but good for realize what can cause the problem. Good luck!

Upvotes: 2

Related Questions