Build RubyMine + Ruby On Rails + MySQL development environment in Windows

Source: Internet
Author: User

Build RubyMine + Ruby On Rails + MySQL development environment in Windows

I recently took over a mobile phone project. Some problems have been encountered during the environment setup process. We have recorded the problems in the following article and offered our solutions.

Development Environment: Windows 2003; JetBrains RubyMine6.3.3

1. download the latest version of ruby(rubyinstaller-2.0.0-p598.exe, the latest version)

Official Website: http://rubyinstaller.org/downloads/

2. Install ruby

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

Here we select the installation path D: \ Ruby200. 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.

3. view the installation result

In Windows, enter ruby-v in cmd to view the ruby version. For example:

Download and install Rails

Run "gem install rails -- include-dependencies" in Windows CMD. If you want to see which packages are installed, enter "gem install rails" to automatically download the program, then there is waiting.

========================================================== ====================

Gem is often slow and sometimes the following error is reported. The solution is to replace it with taobao, as shown below:

This error may be reported when gem install rails

ERROR: cocould not find a valid gem 'rails '(> = 0) in any repository

ERROR: While executing gem... (Gem: RemoteFetcher: FetchError)

$ Gem sources -- remove the http://rubygems.org/

$ Gem sources-a http://ruby.taobao.org/

$ Gem sources-l

* ** Current sources ***

Http://ruby.taobao.org

# Make sure only ruby.taobao.org is supported.

$ Gem install foo

========================================================== ======================================

You can use rails-v to view the version information.

Installation is complete.

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/

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.

Create an empty rails webpage framework

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 project directory under the command line

Rails has a problem. Even if a Gem cannot be installed, it cannot be run. You can ignore it, when that function is used, an error is prompted (Visual Studio is much simpler and more convenient to publish)

This release service took one or two hours, and it was really difficult :)

Bundle install

Run: rails server # Start the service

Webrick introduction:

Ruby already contains a variety of software by default, among which webrick http server is one. This package is used as the default Document Server for rubygem. This is a very simple server written in pure ruby. Interested friends can go to google to get more content.

Open your browser and enter

Http: // 127.0.0.1: 3000

The initialization page is displayed.

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:

Say # hello

The current time is:

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

Class SayController

Or add a link to the goodbye webpage at the end of the hello.html. erb file:

Say Goodbye!

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 of the result 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, and the Code for adding, deleting, modifying, and querying has been generated for us.

>>>> Command to start your rails website on port 888

Rails s-p 888

MySQL on Windows:

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

Important article: Ruby-Linux/Windows installation, code development, and Rails practice

How to Improve Ruby On Rails Performance

Ruby on rails:



Build Ruby On Rails in Ubuntu

Build Ruby on Rails on Ubuntu 13.10

Ruby on Rails 4 Tutorial Chinese Version HD complete PDF

CentOS6.5 use Nginx + Passenger to deploy the Ruby on Rails Environment

Install Ruby on Rails in Ubuntu 15.04

For details about RubyMine, click here
RubyMine: click here

This article permanently updates the link address:

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.