Tutorial on installing and configuring Ruby on Rails development environment in Windows, rubyrails

Source: Internet
Author: User

Tutorial on installing and configuring Ruby on Rails development environment in Windows, rubyrails

This article describes in detail how to configure the Ruby on Rails development environment in Windows, hoping to help beginners of ROR.

1. Download and install Ruby

To install Ruby in Windows, it is best to choose RubyInstaller (one-click installation package ).
: Http://rubyforge.org/frs? Group_id = 167.
Here we download the latest one-click installation package of rubyinstaller-1.9.3-20.exe. In addition to ruby, this installation package also contains many useful extensions (such as gems) and help documents.

Double-click installation. The following page is displayed during installation.

Here we select the installation path D: \ Ruby. The following three options are available: (1) whether to install tclTk. (2) Add the ruby command PATH to the PATH of the system environment variable. (3) Whether to associate the. rb and. rbw files with Ruby.
All of them are checked here. Click "Install.

Open the CMD window and run ruby-v to display the current ruby version number.

You can also enter ruby-e 'puts "hello world" 'to display hello world.

You can also open notepad and write a code such as puts "hello world", save it as test. rb, and run ruby test. rb in CMD to display the result hello world.

I think you can use NotePad to write a program. Here we recommend a lightweight code editor, SciTE, which supports multiple syntax highlighting and exporting, and is free and open-source. Previously, RubyInstaller came with SciTE, and the new version needs to be downloaded by itself. Official Address: scintilla.org windows has the green version and the installation version. Click here to download the installation version.

After installing SciTE, open it and enter the code puts "hello world". Click the menu => file => save to save the file as test. rb. Press F5 on the keyboard, and the result is displayed in the output window on the right.

2. Download and install RubyGems

RubyGems is a convenient and powerful Ruby Package Manager, similar to the RedHat RPM. It packs a Ruby application into a gem and serves as an installation unit. Features: Remote Installation Package, management of dependencies between packages, simple and reliable uninstallation, query mechanism, ability to query package information of local and remote servers, and ability to maintain different versions of a package, you can view information about the installed gem through the Web-based view interface.

Download RubyGems from the official website, take the zip version as an example, uncompress the package, go to the directory of setup. rb in the CMD Prompt window, and run ruby setup. rb to install it.

The newer Ruby version already contains RubyGems, so we do not need to download and install it manually. You only need to enter the command: gem update -- system in the CMD window and wait patiently for a while. The existing RubyGems will be updated to the latest version ..

3. Download and install Rails

Run the command gem install rails in the CMD Prompt window to install rails.

If you do not want to install the document file, enter: gem install rails -- no-rdoc -- no-ri

The program automatically downloads and installs rails, so be patient. :

After the installation is complete, you can see some things in path D: \ Ruby \ lib \ ruby \ gems \ 1.9.1 \ gems. These are all rails package files, which are installed in the same directory as ruby.

In the CMD Prompt window, enter the command: rails-v to display the rails version number.

4. Download and install DevKit

DevKit is a tool for compiling and using local C/C ++ extension packages on windows. It is used to simulate make, gcc, and sh on the Linux platform for compilation. This method currently only supports Ruby installed through RubyInstaller.

Download Devkit: http://rubyinstaller.org/downloads

If the above address cannot be opened, download from here: https://github.com/oneclick/rubyinstaller/downloads/

Here we use a newer version of DevKit-tdm-32-4.5.2-20111229-1559-sfx.exe

Installation steps:

1) decompress the downloaded DevKit to the d: \ DevKit directory.
2) Open the CMD window, enter the D: \ DevKit directory, and enter ruby dk. rb init. # Generate config. yml. Check the list of Ruby supported by DevKit. Only Ruby installed by RubyInstaller is supported.
3) Enter ruby dk. rb install # To start installation.
4) Enter ruby dk. rb review # Check whether the list of Ruby supported by DevKit is correct. You can skip this step.
5) Enter gem install rdiscount -- platform = ruby. # This step only verifies whether DevKit is successfully installed. If rdiscount is successfully installed, it indicates that DevKit is successfully installed or not.


Entire Process

 5. Create a Rails Project

Open the CMD Prompt window, enter disk D, and enter the command: rails new www. A rails project structure named www will be created on disk D.

Go to the www directory and enter the command rails server to start the webrick server that comes with rails.

Open the browser and enter the address http: // localhost: 3000/to view the welcome page, for example:

Let Rails say "Hello"

Rails is an MVC Framework. Rails receives requests from browsers, interprets the requests to find the appropriate controller, and then calls the appropriate method in the controller. Then, control and call the appropriate view to display the result to the user. Rails provides a quick way to create views and control. Open the CMD command window. Go to the www project directory and enter the command: rails generate controller say hello

 

The following View File is displayed in the/project directory/app/views/say/hello.html. erb directory.

Change to the following format:

Copy codeThe Code is as follows:
<H1> Say # hello <P> current time: <% = @ time %> </p>

Note: Save the View File hello.html. erb as the UTF-8 encoding format; otherwise, garbled characters may appear in Chinese. Description is UTF-8 encoding, rather than UTF-8 + BOM encoding, BOM is to add a few characters at the beginning of the file to indicate the file encoding standard. But it is only used by Microsoft. x-nix, PHP, and Ruby are not recognized.

Next, open the Controller file. The path is/project directory/app/controllers/say_controller.rb.

Change

Copy codeThe Code is as follows:
Class SayController <ApplicationController
Def hello
@ Time = Time. now
End
End

Open the browser and access http: // localhost: 3000/say/hello. The result is as follows.

If you want to change the homepage, make the homepage display Hello. Only two steps are required:

1) Find the/project directory/config/route. rb file, find this line # root: to => 'Welcome # Index', remove the comment, set it to your own controller, and change it:

Root: to => 'say # hello'

2) Delete the/project directory/public/index.html file because rails preferentially reads static files under the public directory.

Re-Access: http: // localhost: 3000. The homepage displays "Say # Hello", and the content is consistent.

6. Create a Rails project using the MySQL database

1) Open the CMD window, enter disk D, enter the command rails new work -- database Mysql, and create a rails project structure named work on disk D.

2) You must copy the libmysql. dll library to the Bin directory of the Ruby installation directory (D: \ Ruby \ Bin ). Otherwise, the system prompts "LIBMYSQL. dll is not found, so this application cannot be started. "Re-installing the application may fix this problem ."

: Http://www.mysql.com/downloads/connector/c/

Here we download the mysql-connector-c-noinstall-6.0.2-win32.zip, extract, libmysql. dll in the lib directory is what we are looking.

3) modify the database configuration information. In the/project directory/config/database. yml file, modify the configurations of the "development", "test", and "production" databases to their own configurations.

Among them, development is the database to be used in our development. Be sure to keep at least one space behind username: And password.

4) In the CMD window, enter the rake db: craete command to create the database set in the configuration information in msyql.

5) We use scaffold to generate code and input the following command in CMD:

Rails generate scaffold post title: string body: string addTime: datetime

At this time, the controller, views, models, and database scripts will be created, but no tables have been created yet.

Enter rake db: migrate to create a table. Complete.

6) run the rails server command.

Access the: http: // localhost: 3000/posts page through a browser. The code for adding, deleting, modifying, and querying is generated. OK.


Configure the Ruby On Rails Development Environment

It is best to use InstantRails for development in Windows. There is nothing to do with it.

How to install ruby on rails

It depends on the system you installed.
Installing mac and linux is the same thing.
For more information, see www.javaeye.com/...-linux.
Windows is one thing.

Installing Rails is divided into 2. * or 3. *

If windows is used, xp is strongly recommended.
Do not install Windows 7 or any 64-bit system,

Finally, I will introduce the simplest way for you to try it.
It means you have installed it with instant. Refer to the introduction below, or Baidu rails instant.
Hi.baidu.com/...7.html
Reference: hi.baidu.com/...7.html

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.