In this post I will make first application in Rails after setting development environment.
So lets start, depending on platform we will go to terminal in case of Linux and OS X, or command prompt for Windows. Virtually all Rails application start the same way,with rails command. This handy program creates a skeleton Rails application in a directory of your choice. To get started, make a directory for your Rails projects and then run the rails command to make the first application:
$ mkdir rails_projects
$ cd rails_projects
$ rails new first_app
run bundle install
Fetching source index for https://rubygems.org/
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled
gem is installed.
In Windows after installation of railsinstaller we have a folder for our applications in C:>Sites> , here will be placed my projects in Rails on Windows.
As seen at the end of making first application,running rails automatically runs the bundle install command after the file creation is done. If that step doesn't work right now,don't worry; follow the steps in section bellow under Bundler and should be able to get it work.
Notice how many files and directories the rails command creates. This standard directory and file structure (look bellow) is one of the many advantages of Rails; it immediately gets you from zero to a functional (if minimal) application. Moreover,since the structure is common to all Rails apps, you can immediately get your bearings when looking at someone else's code. A summary of the default Rails files appears in table bellow; we'll learn about most of these files and directories in some of the next posts that will come soon.
Table: A summary of the default Rails directory structure:
app/ Core application(app) code, including models,views,controllers,and
config/ Application configuration
db/ Database files
doc/ Documentation for the application
lib/ Library modules
log/ Application log files
public/ Data accessible to the public (e.g., web browser), such as error pages
script/rails A script for generating code, opening console sessions, or starting a local
test/ Application tests
tmp/ Temporary files
vendor/ Third-party code such as plugins and gems
README.doc A brief description of the application
Rakefile Utility tasks available via the rake command
Gemfile Gem requirements for this app
Gemfile.lock A list of gems used to ensure that all copies of the app use the same gem
config.ru A configuration file for Rack middleware
.gitignore Patterns for files that should be ignored by Git
After creating a new Rails application, the next step is to use Bundler to install and include the gems needed by the app. As noted briefly before, Bundler is run automatically (via bundle install) by the rails command, but in this section we'll make some changes to the default application gems and run Bundler again. This involves opening the Gemfile with your favorite text editor:
$ cd first app/
$ aptana Gemfile # here you put other editor such us sublime,or open in other way
The result should be something like this:
The default Gemfile in the first_app directory
The code in this file is Ruby, but don't worry at this point about the syntax. In first post I recommend a fantastic book for learning Ruby, Programming Ruby 1.9 or older version 1.8,also known as "Pick axe". So it will be more then great to start learning Ruby from this book,also there are a lot other resources that is also very useful.
Unless you specify a version number to the gem command, Bundler will automatically install the latest version of the gem. Unfortunately, gem updates often cause minor potentially confusing breakage, so in this tutorial we'll include explicit version numbers known to work, as seen bellow (which also omits the commented-out lines from up before )
A Gemfile with an explicit version of each Ruby gem