1. Ruby and Rails must be installed successfully
2. Start building the first Web program with the following commands:
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
Step Seventh: Write the there.rhtml below the/app/views/hello directory, which reads as follows:
<title>using Rudy on rails</title>
<h1>welcome to Ruby on rails</h1>
This is your the on Rails applictation
Using this applicaiton,you ' ve been introduced to Controllers,actions,and views.
Not bad for a-a-example!
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