3.1 Installing Rails
Open up a command line prompt. On Mac OS X open Terminal.app, on Windows choose "Run" from your Start menu and type 'cmd.exe'. Any commands prefaced with a dollar sign
$ should be run in the command line. Verify that you have a current version of Ruby installed:$ ruby -vruby 1.9.3p385 |
To install Rails, use the
gem install command provided by RubyGems:$ gem install rails |
A number of tools exist to help you quickly install Ruby and Ruby on Rails on your system. Windows users can use Rails Installer, while Mac OS X users can use Rails One Click.
To verify that you have everything installed correctly, you should be able to run the following:
$ rails --version |
If it says something like "Rails 4.0.0", you are ready to continue.
3.2 Creating the Blog Application
Rails comes with a number of scripts called generators that are designed to make your development life easier by creating everything that's necessary to start working on a particular task. One of these is the new application generator, which will provide you with the foundation of a fresh Rails application so that you don't have to write it yourself.
To use this generator, open a terminal, navigate to a directory where you have rights to create files, and type:
$ rails new blog |
This will create a Rails application called Blog in a directory called blog and install the gem dependencies that are already mentioned in
Gemfile using bundle install.
You can see all of the command line options that the Rails application builder accepts by running
rails new -h.
After you create the blog application, switch to its folder to continue work directly in that application:
$ cd blog |
The
rails new blog command we ran above created a folder in your working directory called blog. The blog directory has a number of auto-generated files and folders that make up the structure of a Rails application. Most of the work in this tutorial will happen in the app/ folder, but here's a basic rundown on the function of each of the files and folders that Rails created by default:
No comments:
Post a Comment