Ruby on Rails Primer Example (Ruby1.8.6 gem 1.3.1 Rail 2.2.3)

Source: Internet
Author: User
Tags sqlite sqlite database ruby on rails

1. Ruby and Rails must be installed successfully

2. Start building the first Web program with the following commands:

C:/>MD Rubydev

C:/>CD Rubydev

c:/rubydev>rails-d MySQL A

It is worth noting that the original command to establish the program should be: rails one, but if you follow this command, you will get an error:

"No such file to load-sqlite3".

It is estimated that no SQLite database was found, opened Database.yml, and found that rails has automatically added SQLite configuration to me. Furthermore, the command to install the SQLite driver is also given. However, I do not want to use SQLite. Check the Internet, the original Rails upgrade to 2.0.2 after the use of Sqlite3 as the default database.

3. Modify the file database.yml below config, and set all of the database inside blank. Do not modify the words will be the error, in addition to fill in the pwd of your own MySQL password. ---------------is very important ...

4. Input: Ruby Script/server, enter http://localhost:3000 in the browser, will display the main interface

5. Well, since it's the MVC pattern, let's create the controller first.

The command line is as follows: Ruby script/generate Controller Hello

This produces a controller that corresponds to the c:/rubydev/first/app/controllers hello_controller.rb

Create an action, which is to modify the contents of the C:/rubydev/first/app/controllers hello_controller.rb file as follows:

Class Hellocontroller < Applicationcontroller
def there
End
End

Step Seventh: Write the there.rhtml below the/app/views/hello directory, which reads as follows:

<title>using Rudy on rails</title>
This is your the on Rails applictation
<br>
<br>
Using this applicaiton,you ' ve been introduced to Controllers,actions,and views.
<br>
<br>
Not bad for a-a-example!
</body>

Eighth step: Input: Ruby script/server, browser input http://localhost:3000/hello/there, the interface came out. Indicates success

Note: When using MySQL, you will be prompted no such file to load-MySQL, the solution is as follows:

Ruby Connection to MySQL on Win32 (Turn)

 
1. First installed MySQL the latest should be 5.0

2. Install MySQL driver for Ruby, install method please own on-line inquiry, can use gem install MySQL Remote installation directly (must install MySQL drive successfully)


2. Find mysql_api.so under d:/ruby/lib/ruby/gems/1.8/gems/mysql-2.8.1-x86-mswin32/lib/1.8

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.