Saturday, March 19, 2016

Creating the First Application Ruby on Rails

Creating the First Application Ruby on Rails. The best way to use this guide is to follow each step as it happens, no code or step needed to make this example application has been left out, so you can literally follow along step by step.

By following along with this guide, you'll create a Rails project called blog, a (very) simple weblog. Before you can start building the application, you need to make sure that you have Rails itself installed.

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:
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 Tokaido.

$ ruby -v
ruby 2.0.0p353
To install Rails, use the gem install command provided by RubyGems:
$ gem install rails
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.2.1", you are ready to continue.

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
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:
$ cd blog
File/FolderPurpose
app/Contains the controllers, models, views, helpers, mailers and assets for your application. You'll focus on this folder for the remainder of this guide.
bin/Contains the rails script that starts your app and can contain other scripts you use to setup, deploy or run your application.
config/Configure your application's routes, database, and more. This is covered in more detail in Configuring Rails Applications.
config.ruRack configuration for Rack based servers used to start the application.
db/Contains your current database schema, as well as the database migrations.
Gemfile
Gemfile.lock
These files allow you to specify what gem dependencies are needed for your Rails application. These files are used by the Bundler gem. For more information about Bundler, see the Bundler website.
lib/Extended modules for your application.
log/Application log files.
public/The only folder seen by the world as-is. Contains static files and compiled assets.
RakefileThis file locates and loads tasks that can be run from the command line. The task definitions are defined throughout the components of Rails. Rather than changing Rakefile, you should add your own tasks by adding files to the lib/tasks directory of your application.
README.rdocThis is a brief instruction manual for your application. You should edit this file to tell others what your application does, how to set it up, and so on.
test/Unit tests, fixtures, and other test apparatus. These are covered in Testing Rails Applications.
tmp/Temporary files (like cache, pid, and session files).
vendor/A place for all third-party code. In a typical Rails application this includes vendored gems.

Hello, Rails!

To begin with, let's get some text up on screen quickly. To do this, you need to get your Rails application server running.

Starting up the Web Server

You actually have a functional Rails application already. To see it, you need to start a web server on your development machine. You can do this by running the following in the blog directory:
$ bin/rails server
To see your application in action, open a browser window and navigate to http://localhost:3000. You should see the Rails default information page:


Reference : http://guides.rubyonrails.org/

Bagikan

Jangan lewatkan

Creating the First Application Ruby on Rails
4/ 5
Oleh