Rails s and rails console not working - ruby-on-rails

I haven't used Ruby in a while, so I just came back to it today and whenever I try to do rails s or rails console it spits out the generic help text, i.e.
rails console ~
Usage:
rails new APP_PATH [options]
Options:
-r, [--ruby=PATH] # Path to the Ruby binary of your choice
# Default: /Users/cabelhigh/.rvm/rubies/ruby-1.9.2-p320/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
It just does this over and over. Any idea what's wrong?
Also, I'm running OSX, if that has anything to do with it.
EDIT: Version info: Rails 3.2.8, ruby 1.9.2p320 (2012-04-20 revision 35421) [x86_64-darwin11.3.0]

You are not in a rails application directory when you execute the commands
Make a new rails app with
rails new blog
cd into the directory
cd blog
and run
rails s
or
rails c

rails console works only in Rails project directory

Rails console work only in rails project directory.
May be you want run ruby console? (like irb, pry, etc)

Related

Fresh Rails 4 app is not recognizing `rails` commands, insists that I use `rails new`

I've successfully made a new application with the rails new command from a clone of the Rails master branch. The app looks fine, and is definitely Rails 4. But when I try to run any other rails command, the prompt gives me:
Usage:
rails new APP_PATH [options]
Options:
-r, [--ruby=PATH] # Path to the Ruby binary of your choice
... etc etc
I've tried rails, bundle exec rails, and bin/rails, all give the same prompt. My steps for creating a new Rails 4 app were:
Clone the Rails master branch to my local machine
Create a new rvm gemset, and use it (1.9.3)
Run rails/railties/bin/rails new myapp --edge -T --skip-index-html
cd myapp and run bundle install and bundle update just to be sure
Run any rails command
What am I doing wrong? rvm-prompt suggests I am using the right gemset. One thing I did notice is that even when I remove jbuilder from my Gemfile and run a bundle update, it still appears in my gem list. Is something wrong with my rvm here?
rails-v output is 'Rails 4.0.0.beta'
See my first comment here, it contains a possible fix : https://github.com/rails/rails/issues/9715
This looks like a bug, report back to ruby on rails issues tracking: https://github.com/rails/rails/issues
I had this issue when my 'bin' folder was missing.

"rails server" on existing working application not starting

I'm happily configuring my new laptop to work on my already existing projects.
I copied the folder of an application and all its subfolders, and now have it in the new laptop.
It seems I cannot start the server by typing rails server command at the root of the project.
I tried to create a new project and start it and it works just fine, so I really have no idea of what to do. Rails versions are the same and identical Gemfile.
This is the result of the rails server command:
Usage:
rails new APP_PATH [options]
Options:
-r, [--ruby=PATH] # Path to the Ruby binary of your choice
# Default: /home/toni/.rvm/rubies/ruby-1.9.3-p374/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
ETC...
thanks!
In Rails 3.x, this will occur when script/rails is missing. The file could accidentally have been deleted or it may have never been committed to source control if you've just cloned the project to another machine. You'll need to find or regenerate it.
Rails determines if it's actually "in" a Rails project by checking if script/rails exists. If it doesn't find that file, it assumes it's not a Rails project:
https://github.com/rails/rails/blob/v3.2.21/railties/lib/rails/script_rails_loader.rb#L21-L23
There is an option you can pass 'rails new' to ignore files that already exist:
rails new APPNAME -s
You could try running that over your existing project to replace any missing files.
See also:
http://guides.rubyonrails.org/v3.2.13/initialization.html
Judging from the output of the rails command it seems that you do not execute the command 'rails server' in the root directory of a rails project.
You should check if you are in the correct directory and if all files have been copied.

I can't run my Rails web server

I have installed ruby193 and I've installed rails via the command prompt. However, whenever I try the command:
ruby script/server
I get this error:
ruby: No such file or directory -- script/server (LoadError)
I checked my script folder and all it has is a file called rails.
I'm very new to Ruby on Rails and I'm not entirely sure if I've installed everything correctly. Is there an easy way to check what I have installed?
To clarify on the existing answers, ruby script/server is no longer the proper way to start a server in Rails. In Rails 3, we use rails server, which can be shortened to rails s. See the Rails Guides for a more extensive rundown of the Rails 3 command line interface.
Try running rails server or rails s.
If you have Ruby & rails installed properly, then ruby -v would result in the version that you have installed and likewise rails -v would give the rails version installed.
To run a rails server try running rails server or rails s

Why rails console did not fire up on ubuntu with rails 3.1.3

When type rails console under the deploy subdir on ubuntu, instead of firing up the console, it displays help message for rails:
Usage:
rails new APP_PATH [options]
Options:
-r, [--ruby=PATH] # Path to the Ruby binary of your choice
However irb can fire up without error. Anyone knows why? Thanks so much.
Check this answer here: typing 'rails console' doesn't start?
You need to make sure that your current directory is the base directory of a rails app, because the rails console command needs to load the environment of that app.

Entering Rails commands in Terminal, Help is returned

When I enter:
$ rails server
I get this returned for and rails commands entered:
Usage:
rails new APP_PATH [options]
Options:
[--edge] # Setup the application with Gemfile pointing to Rails repository
[--dev] # Setup the application with Gemfile pointing to your Rails checkout
-G, [--skip-git] # Skip Git ignores and keeps
-m, [--template=TEMPLATE] # Path to an application template (can be a filesystem path or URL)
-b, [--builder=BUILDER] # Path to a application builder (can be a filesystem path or URL)
[--old-style-hash] # Force using old style hash (:foo => 'bar') on Ruby >= 1.9
[--skip-gemfile] # Don't create a Gemfile
-d, [--database=DATABASE] # Preconfigure for selected database (options: mysql/oracle/postgresql/sqlite3/frontbase/ibm_db/sqlserver/jdbcmysql/jdbcsqlite3/jdbcpostgresql/jdbc)
# Default: sqlite3
-O, [--skip-active-record] # Skip Active Record files
[--skip-bundle] # Don't run bundle install
-T, [--skip-test-unit] # Skip Test::Unit files
-S, [--skip-sprockets] # Skip Sprockets files
-j, [--javascript=JAVASCRIPT] # Preconfigure for selected JavaScript library
# Default: jquery
-J, [--skip-javascript] # Skip JavaScript files
-r, [--ruby=PATH] # Path to the Ruby binary of your choice
# Default: /usr/bin/ruby1.8
Runtime options:
-s, [--skip] # Skip files that already exist
-f, [--force] # Overwrite files that already exist
-p, [--pretend] # Run but do not make any changes
-q, [--quiet] # Supress status output
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.
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.
Why doesn't it initiate the server? To me this appears to be a rails helpDoc or some such.
Similar also happens for:
$ rails generate
Is there anything i can do to get these commands to initiate properly...
I'm using Rails version 3.1.3, on Ubuntu.
BTW: I am entering these from within the directory of myapp i.e.
chuckles#.......:~/Blog/new$
I did get the server to start by running:
$ script/server
from /new/
I had this issue. Turns out I created a gemset to use with my app, then when I switched to the app folder in terminal it reverted to the default gemset which didn't support my application.
You can check which gemset your using by doing
rvm gemset list
So inside of my app folder I switched to the appropriate gemset using.
rvm gemset use [your gemset name]
Then
bundle install
to update the gem files.
Everything worked fine afterwards.
If you have 'script/server', then you probably have rails 2.x application, instead of 3.x. Make sure (rails -v) that you run rails 3.x.x gem, instead of 2.x.
EDIT:
I wasn't clear enough probably. From informations you provided I see:
you have rails 3.x gem, and it shows you help screen, because it can't find Rails 3.x application
you have application generated by rails 2.x gem (you have script/server script, and you can verify that your application is for older rails by looking at config/environment.rb file)
This combination won't work. You need to do something with it. If you need this old application, then you could uninstall rails 3.x gem and install 2.x verison. It would be even better if you could migrate this application to run with bundler (then you don't need to uninstall rails 3.x gem), but if it's not possible, you can take a look at rvm's gemsets.
What I do when I need to start old application:
rvm use ree - if my application uses Ruby Enterprise Edition on server, otherwise rvm use [ruby version here], depending which version
rvm gemset create [application name here] - to make gemset specific for this application
rvm alias create [application name here] ree#[gemset name here] - to make sure I can get back to this gemset quick
rvm use [alias name here] - to switch to application ruby-gemset combination
install all gems required by application (ask other developers which versions should you use and how to install them
Then whenever I go back to developing this application:
rvm use [alias name here]
./script/server - to start application
You also need to look for tutorial and documentation for Rails 2.x if you want to develop with this version.
You can only run these commands from inside an existing rails project folder. Check out the bottom of the output where it gives you an example command to create the skeleton structure of a rails project.
Alternatively, run through this tutorial
http://guides.rubyonrails.org/getting_started.html
You need to be inside a rails project directory to run these commands. First, create a new project:
rails new myapp
then you can move into it and run the server or other commands.
cd myapp
rails server
Check your bin directory in rails app root directory, I have removed that and It was causing problem for me. Create a bin directory and copy these files at least.
bundle rails rake
from any other rails project.

Resources