0

I am trying to generate a controller in my rails app using the following command:

rails generate controller CreditCard

but it simply returns me the following:

Usage:
  rails new APP_PATH [options]

Options:
  -r, [--ruby=PATH]              # Path to the Ruby binary of your choice
                                 # Default: /export/data0/home/tanya/.rvm/rubies/ruby-1.9.3-p448/bin/ruby
  -b, [--builder=BUILDER]        # Path to a application builder (can be a filesystem path or URL)
  -m, [--template=TEMPLATE]      # Path to an application template (can be a filesystem path or URL)
      [--skip-gemfile]           # Don't create a Gemfile
      [--skip-bundle]            # Don't run bundle install
  -G, [--skip-git]               # Skip Git ignores and keeps
  -O, [--skip-active-record]     # Skip Active Record files
  -S, [--skip-sprockets]         # Skip Sprockets files
  -d, [--database=DATABASE]      # Preconfigure for selected database (options: mysql/oracle/postgresql/sqlite3/frontbase/ibm_db/sqlserver/jdbcmysql/jdbcsqlite3/jdbcpostgresql/jdbc)
                                 # Default: sqlite3
  -j, [--javascript=JAVASCRIPT]  # Preconfigure for selected JavaScript library
                                 # Default: jquery
  -J, [--skip-javascript]        # Skip JavaScript files
      [--dev]                    # Setup the application with Gemfile pointing to your Rails checkout
      [--edge]                   # Setup the application with Gemfile pointing to Rails repository
  -T, [--skip-test-unit]         # Skip Test::Unit files
      [--old-style-hash]         # Force using old style hash (:foo => 'bar') on Ruby >= 1.9

Runtime options:
  -f, [--force]    # Overwrite files that already exist
  -p, [--pretend]  # Run but do not make any changes
  -q, [--quiet]    # Suppress status output
  -s, [--skip]     # Skip files that already exist

Rails options:
  -h, [--help]     # Show this help message and quit
  -v, [--version]  # Show Rails version number and quit

Description:
    The 'rails new' command creates a new Rails application with a default
    directory structure and configuration at the path you specify.

    You can specify extra command-line arguments to be used every time
    'rails new' runs in the .railsrc configuration file in your home directory.

    Note that the arguments specified in the .railsrc file don't affect the
    defaults values shown above in this help message.

Example:
    rails new ~/Code/Ruby/weblog

    This generates a skeletal Rails installation in ~/Code/Ruby/weblog.
    See the README in the newly created application to get going.

Even running 'rails console' return me the same message.I don't understand why the generate command does not work.

I am currently using rails 3.2.13 and ruby 1.9.3.

Thanks a lot for your help.

4
  • Looks like you are running Rails 3 commands in Rails 2 or lower.Are you sure that your Rails version is 3.2.13? Commented Aug 11, 2014 at 11:22
  • Doing 'rails -v' returns me Rails 3.2.13 Commented Aug 11, 2014 at 11:25
  • Well,running your command in Rails 2 returns the same message for me. Commented Aug 11, 2014 at 11:32
  • The version of the rails command line does not necessarily reflect the version of rails that is installed in your app. To make sure the same version is used try bundle exec rails .... Prefixing your command with bundle exec instructs bundler to use the version of the gem that is bundled with your app. Do you still get the same behavior if you do this? Commented Aug 11, 2014 at 11:40

3 Answers 3

1

I think you are not in rails application directory. Please check path and run command again.

This message generally occurred when you try to run generate controller command out of application directory.

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

2 Comments

I am in the rails app directory
I have tried same on my end and getting this error when I am out of application directory only. One more thing you are using rails 3 or above. So don't worry about rails version. If you run this command in rails 2 then it will create new app with name generate each time.
1

I think you are not running the command inside Rails root directory.You have to navigate to the application before running the rails generators.If you have an application named blog then follow the below commands

cd blog
rails g controller posts

Comments

0

Thanks a lot for all you suggestions. What I did was simply to create a new application using rails new new_app and copy the files of my original rails application to this new directory. After I did that, it seems to work fine. I must have messed up something in the original application folder.

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.