How to run "rails s" - ruby-on-rails

I have a problem running rails s in Ubuntu. When I type rails s it doesn't start the server, but instead it outputs:
kyala#ubuntu:~/depot$ rails s
Usage:
rails new APP_PATH [options]
Options:
-r, [--ruby=PATH] # Path to the Ruby binary of your choice
# Default: /home/kyala/.rvm/rubies/ruby-1.9.2-p290/bin/ruby
-d, [--database=DATABASE] # Preconfigure for selected database (options: mysql/oracle/postgresql/sqlite3/frontbase/ibm_db)enter code here
# Default: sqlite3
-b, [--builder=BUILDER] # Path to an application builder (can be a filesystem path or URL)
-m, [--template=TEMPLATE] # Path to an application template (can be a filesystem path or URL)
[--dev] # Setup the application with Gemfile pointing to your Rails
checkout
[--edge] # Setup the application with Gemfile pointing to Rails
repository
[--skip-gemfile] # Don't create a Gemfile
-O, [--skip-active-record] # Skip Active Record files
-T, [--skip-test-unit] # Skip Test::Unit files
-J, [--skip-prototype] # Skip Prototype files
-G, [--skip-git] # Skip Git ignores and keeps
Runtime options:
-f, [--force] # Overwrite files that already exist
-p, [--pretend] # Run but do not make any changes
-q, [--quiet] # Supress status output
-s, [--skip] # Skip files that already exist
Rails options:
-v, [--version] # Show Rails version number and quit
-h, [--help] # Show this help message 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.

Try to regenerate binstubs:
rm bin/*
rake rails:update:bin
It should do the trick.
For newer (5.2+) Rails versions use
rake app:update:bin

When the script folder is missing from the Rails application folder it shows the above error.
I just copied it from another app and it worked for me.

Before running the Rails server, you need to first create a Rails application.
For example, to create a new app call "test_app", run the following:
rails new test_app
Once your application is created, you can cd into the directory and start your server:
cd test_app
rails server

OK guyz just for the closure... this problem occurs only when we delete some(mostly script) folders in the rails app... (may be.. accidentally.).. I had this issue but was in a wrong app folder...

My first hunch would be that you are not in the root of your Rails application.
On our deployment servers, I have to type
./script/rails s
when in the root-folder of my Rails-app. I think that is because bin\rails is not known there.
If that would not work, it seems to me that you are not at all inside a Rails root folder, which would also explain why rails s did not work.
A Rails root project will contain at least the following directories: app, lib, config, script ....

I've seen a similar issue with Rails 2.x apps. They fire up fine with thin, unicorn and such, but to get just the webrick server I've had to run bundle exec script/server (or for the less careful script/server seems to work). I don't know the root issue at play here, but this seems to tide me over as I don't maintain any rails 2.x code (simply running ChiliProject 3.x, etc.).

We had the same problem.
Be sure you run the 'rails' command in the script folder and not the binary 'rails' that is different
script/rails s
It´s the same that if you go to your script folder and run the command:
cd script
./rails s

Check whether the 'script' folder exists in your application structure.

I had the same issue. I had forgotten to run bundle after creating an app.
From the root of your project directory run:
bundle install

Run the following command inside your project folder:
rails s
Your project folder contains node_modules, Gemfile.lock, etc...

While searching for an answer myself, I ended up trying a few things that proved useful to getting rails s to work for me. This resulted in 658 files changed, 102204 insertions, and 149 deletions.
Look at the file that you're in by running ls.
Run git status.
Run git add ..
Run git commit -m "Notate whatever changes you are adding to github repository".
I tried to run git push and git push master but neither work, "go figure." My guess is that you can't push changes that belong to a different file or branch.
HERE's THE SECRET... For some strange reason, I was working in a different file so I had to run a git pull YourOtherFile. This is where everything started making sense.
Now, I ran another git status to understand what was going on within this file. There was modified and untracked content.
Next, cd back into the other file.
Run git status to view all of your modified and untracked files.
Run git add . and git commit -m "Notate your changes to this repository".
Watch the magic happen then run a git push.
Run gem update bundler.
Then I ran gem install rails_12factor.
Run another git status to view your modification.
Run git commit -m "Successfully added gem rails_12Factor".
Run git push.
I had issues with bcrypt being locked at 3.1.11 so I ran gem install 'bcrypt'.
Run gem install rails_12factor yet again. I believe that I had the "f" in "factor" capitalized.
Run gem update.
Run gem install pg.
Run git add ..
Run git commit -m "Updated Gemfile".
Run git push.
Run gem install 'pg' yet again.
I was running into all kind of issues but it was because I was trying to upgrade my gemfile to Rails 5.
Run gem install railties.
Run gem install activesupport.
If your Gemfile was already in another version of Rails (gem 'rails', '4.2.6'), make sure that you keep it there as there was not a significant difference in Rails 5.

Just Run 'bundle update' command and start your application

Try "rails server" instead of the short form. Maybe you have it aliased for some reason.

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 4 doesn't detect application

After updating to Rails 4, I'm trying to start the server, but it won't start. Simply put, the application doesn't seem to get "detected", like there is no application in there.
~ $ bundle exec rails server
Usage:
rails new APP_PATH [options]
Options:
-r, [--ruby=PATH] # Path to the Ruby binary of your choice
# Default: /app/vendor/ruby-2.0.0/bin/ruby
-b, [--builder=BUILDER] # Path to some application builder (...
-m, [--template=TEMPLATE] # Path to some application template (...
[--skip-gemfile] # Don't create a Gemfile
-B, [--skip-bundle] # Don't run bundle install
What is weird is that the (older) system gem will make it start just fine, but not with Bundler.
Why won't Rails start?
I tried navigating the CLI source code, but I can't grip what's going on.
(Using Edge Rails 4.0.0.beta and Ruby 2.0.0.rc)
In case you're wondering, here's the directory listing:
~ $ ls
app config db Gemfile lib mock Rakefile script tmp
bin config.ru features Gemfile.lock log public README.md spec vendor
Rails 4 did change the way it boots up.
Fortunately, you don't have to run rails-new, since there is a handy task for that.
Rails 4 Release Notes:
6.1  Notable changes
Your app's executables now live in the bin/ dir. Run rake rails:update:bin to get bin/bundle, bin/rails, and bin/rake.
Mostly, I've been had by my own laziness. (Even though laziness is the mother of efficiency ;o) ) I've made a point of not using Bundle when running Rails server.
Rails 4.0.0.beta changes the way it boots up. But, since I was using my "old" version of Rails, an older 4.0.0-beta I had lying around in my local gems, which didn't have the change, I didn't notice when the change was made to my bundle.
Now, when came the time to deploy, the obligatory bundle-exec couldn't boot because my code was used to boot the old way.
The solution
Do like the message says to: bundle exec rails new .. And use Bundle this time! At that point, Rails will generate the boilerplate stuff, namely the missing boot files like ./bin/rails.
It will also update some config files, and try to overwrite some stuff. In my case, everything is checked into source control, so there's a bit of diff'ing and choosing whether to overwrite or not and reverting after.
An maybe better idea (I haven't bothered to) would be to branch out in Git, run the "upgrade" rails-new, overwrite everything, commit that, and then three-way merge back with the main branch.
If your bin folder is already in place, you may just need to run bundle install first. This solved the problem for me after cloning a repo that was working perfectly on another machine.

"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.

how to run rails project after doing checkout using svn?

i have checked out a rails project into my svn repository.now i want to run that project on my local server.I entered rails server command to run it but i am getting an error that it cant find or read .yml file.what are the steps to be taken after one checks out some rails project in order to run it on local server.
cd into the directory containing the Gemfile and then do either rails s or bundle exec rails s. The error you are describing usually happens to me when I am not in the same dir as the Gemfile and Rails cannot find the database.yml file.

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