cd to the folder where you want to store your new application. For me, this is ~/code. Then,
rails new my_appThis creates a subfolder called my_app and puts all of the boilerplate for a Rails application inside.
For all subsequent commands, you must cd in to the application folder first.
cd in to the folder you just downloaded. Then,
bundle installThe bundle install (or just bundle for short) command fetches all of the 3rd party Ruby code that the application depends upon and installs it on your machine. You only need to do this once per application.
rails serveror rails s for short.
If the server started successfully, you should see output like the following. It may take a moment.
=> Booting WEBrick
=> Rails 4.2.1 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
[2015-04-27 10:14:28] INFO WEBrick 1.3.1
[2015-04-27 10:14:28] INFO ruby 2.2.1 (2015-02-26) [x86_64-darwin14]
[2015-04-27 10:14:28] INFO WEBrick::HTTPServer#start: pid=15767 port=3000and then the cursor should be blinking at the bottom, but not at the end of your usual command prompt. This window is now dedicated to the web server app, and you can't run any other commands in it until you shut down the server.
If you need to run other command line stuff, open up a new window or tab.
- If you got a "address already in use" error, then you must have an old
rails serverrunning in another window or tab somewhere. Find it and Ctrl-C (or just close the tab). - If you have a syntax error in config/routes.rb, then the server will refuse to even start up. See if the error message complains about a line in that file.
Ctrl-C. On Windows, you may be asked whether to terminate the job; say yes.
rails consoleor rails c for short.
Rails Console is a superpowered version of IRB, handy for testing snippets of code.
If the application you cloned requires database setup, then
rake db:migrate
will create the tables and columns. If I provided some starter dummy data for you, then
rake db:seed
will quickly pre-populate the tables for you, so you don't have to spend an hour in rails console adding rows.
If your bundle install fails with a message like this:
Gem::RemoteFetcher::FetchError: SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verifythen open the file called Gemfile in the root folder of the application with Atom and change
source 'https://rubygems.org'
to
source 'http://rubygems.org'
(remove the "s"). Save and then bundle install again.
This is only a temporary fix. Long term, you should find a permanent solution or switch to a different development environment (Linux, OS X, or a cloud environment like Nitrous.io or Cloud9).
I am getting an error relating to ExecJS or TypeError: Object doesn't support this property or method
Go in to the app/assets/javascripts/application.js file and delete the line
//= require_tree .
Refresh the page in Chrome; it should now be okay.
If you are still experiencing an error, try the following also:
-
In
Gemfile, delete the linegem 'turbolinks' -
In
app/assets/javascripts/application.js, delete the line//= require turbolinks -
bundle installand restart your server.
When I try to create a new application, I get the below message:
An error occurred while installing byebug (5.0.0), and Bundler cannot continue. Make sure that 'gem install byebug -v '5.0.0'' succeeds before bundling.
How do I fix this?