2--windows: RubyMine + Ruby on Rails + MySQL build development environment

Source: Internet
Author: User
Tags ruby on rails

Recently took over a mobile phone project. In the process of setting up the environment, some problems have been encountered, recorded in the following, and a personal solution.

Development environment Win2003; 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 Install, the installation process appears the following interface.

Here we choose the installation path to D:\Ruby200. The following 3 options are: (1) Whether TCLTK support is installed. (2) Add the Ruby command path to the system environment variable path. (3) whether the. RB and. rbw files are associated with Ruby. here we all tick. Click "Install" to complete the installation.

3. View the installation results

In the Windows environment, CMD Input: Ruby–v view the ruby version. Such as:

Download and install Rails

Run "gem install Rails--include-dependencies" in Windows CMD, if you want to see all the packages, enter "gem Install Rails", The program is downloaded automatically, and then the rest is waiting.

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

Gems are often slow, and sometimes the following errors are reported, and solutions are resolved to replace them with Taobao, as follows:

Gem install rails , this error may be reported error:  could not find a valid  gem  ' Rails '   (>= 0)  in any repository

$ gem Sources--remove http://rubygems.org/ $ gem sources-a http://ruby.taobao.org/ $ gem sources     -L * * * * Current SOURCES * * http://ruby.taobao.org # Please make sure only ruby.taobao.org $ gem install foo

After the ================================================================== is complete, you can also use Rails-v to view the version information.

Installation is complete.

Download and install Devkit

DevKit is a tool for compiling and using the local C + + expansion pack under the Windows platform. It is used to simulate the make, GCC, sh to compile on the Linux platform. This method currently supports only Ruby that is installed through Rubyinstaller.

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

If the above address is not open, download it from here: https://github.com/oneclick/rubyinstaller/downloads/

Installation steps:

1) Unzip the download DevKit to the D:\DevKit directory. 2) Open the CMD window, enter the D:\DevKit directory, and enter the Ruby DK.RB init. #生成config. Yml, this examines the list of Ruby that will be added Devkit support, only Ruby that is installed through Rubyinstaller. 3) Enter the ruby dk.rb install #开始安装. 4) input ruby DK.RB review #检查要添加DevKit支持的Ruby列表是否有误, can skip. 5) Enter the gem install Rdiscount--platform=ruby. #这一步只是验证DevKit是否安装成功, if you can install the Rdiscount successfully stating that the installation Devkit successful, you can not do it.

Create an empty Rails Web page frame

Open the cmd Prompt window, enter D, enter command: Rails new WWW, will create a rails project structure named www in the D disk.

Go to the project directory under the command line

Rails has a problem, even if there is a Gem can not be installed is not able to run, in fact, may be ignored, to use that feature when the error (Visual studio release is more concise and convenient)

This release service, took one or two hours of time, really not easy:)

Bundle Install

Running:rails Server #启动服务

Webrick Introduction: Ruby By default already contains rich software, where Webrick HTTP server is one of them. 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 for more content.

Open Browser input

http://127.0.0.1:3000

You can see the initialization page.

Down we let rails say "Hello"

Rails is an MVC framework that rails receives requests from the browser, interprets the request to find the right controller, and then invokes the appropriate method in the controller. Then, the control invokes the appropriate view and displays the results to the user. Rails provides a quick way to create views and controls to open the CMD command window. Go to the WWW project directory, enter the command: Rails generate controller Say hello

Below I open the hint in the view file, path is/project directory/app/views/say/hello.html.erb

Modify to the following form:

    

Note: Save the View file Hello.html.erb as the UTF-8 encoding format, otherwise the Chinese will appear garbled. Description is UTF-8 encoding, instead of UTF-8 +bom encoding, the BOM is the standard for file encoding by adding several characters at the beginning of the file. But only Microsoft used, X-nix, PHP, Ruby do not recognize.

Then open the controller file, the path is/project directory/APP/CONTROLLERS/SAY_CONTROLLER.RB

Revision changed to

  Class Saycontroller < Applicationcontroller     def hello        @time =time.now      End    End

Or, at the end of the Hello.html.erb file, add a link to the Goodbye Web page:

<p>

Say <a href= "Say/goodbye" >goodbye</a>!

</p>

Open browser access: Http://localhost:3000/say/hello, results such as.

If you want to change the homepage, let the first page show Hello. Only 2 steps:

1) Find/project directory/config/route.rb file, find this line # root:to = ' Welcome#index ' Remove the comment and set it to its own controller, modified to:

root:to = ' Say#hello '

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

Visit again: http://localhost:3000/, home display Say#hello, the content is consistent.

Six create a rails project that uses a MySQL database

1) Open the cmd window, enter D, enter command: Rails new work--database Mysql, create the Rails project structure named work in the D disk.

2) The Libmysql.dll library must be copied to the Bin directory of the Ruby installation directory (D:\Ruby\Bin). Otherwise, you will be prompted when you start the server: "LIBMYSQL.dll was not found, so the application failed to start." Reinstalling the application may fix the problem. ”

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

We download mysql-connector-c-noinstall-6.0.2-win32.zip here, unzip, in the Lib directory inside the Libmysql.dll is what we are looking for.

3) Modify the configuration information for the database. In the/project directory/config/database.yml file, respectively, corresponding to the "development", "test", "Production" database configuration, modify them to their own configuration.

Where development is the database we are actually using in our development. Be sure to note that at Username: and password: At least one space is left behind.

4) Enter the Rake db:craete command in the CMD window and the database set in the configuration information will be created in MSYQL.

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

Rails Generate scaffold Post title:string body:string addtime:datetime

The controller, views, models, and database scripts are created at this time, but no table is created yet.

Re-enter: Rake db:migrate create table. Complete.

6) Execute Command Rails server

Access via Browser: http://localhost:3000/posts This page has generated additions and deletions for us to change the code.

>>>> command to launch your Rails website on port 888

Rails s-p 888MySQL on Windows:http://dev.mysql.com/downloads/connector/c/

2--windows: RubyMine + Ruby on Rails + MySQL build development environment

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.