This article comes from: Web development agility-applying rails for agile web development (version 4)
Environment:
Ruby 1.9.3p392 () [i386-mingw32]
Rails 3.2.13
Gem 2.0.3
SQLite
1. Configure the ROS environment in Windows
Use the rubyinstaller installation package. For detailed installation methods, see composer;
2. Hello world!
Run cmd;
Rails news demo
CD demo
Rails s
The above command creates a simple example,
Rails generate controller say hello goodbye // create a controller say. You can understand that say is a class, and hello and goodbye are two methods in the class;
Go to the demo directory and open ../demo/APP/contrallers/say_controller.rb. The following figure is displayed:Code
Class saycontroller <applicationcontroller
Def hello
End
Def goodbye
End
End
Enter URL: http: // localhost: 3000/say/hello in the browser.
Show say # Hello ·····
Then we open the file on this page (located in ../demo/APP/hello.html. ERB) and replace the code in it.
<H1> Hello World
Refresh: http: // localhost: 3000/say/Hello
3. simple dynamic page
Export the following code to hello.html. ERB
<P> it is now <% = time. Now %>
The current time will appear when loading http: // localhost: 3000/say/hello.
Now we need to make some improvements to the above Code.
Open ../demo/APP/controller/say_controller.rb and modify the Code as follows:
Class saycontroller <applicationcontroller
Def hello
@ Time = time. Now
End
Def goodbye
End
End
The hello.html. ERB code is modified:
<H1> Hello form rails! </H1>
<P> it's now <% = @ time %> </P>
Refresh http: // localhost: 3000/say/hello.
4. link_to
The hello.html. ERB code is modified:
<H1> Hello form rails! </H1>
<P> it's now <% = @ time %> </P>
<P> time to say
<% = Link_to "goodbye", say_goodbye_path %>!
</P>
Now there will be the following sentence on the page: Click to link to http: // localhost: 3000/say/goodbye.
Then we modify goodbye.html. ERB.
<H1> goodbye! </H1>
<P> It was nice having you here. </P>
<P>
Say <% = link_to "hello", say_hello_path %> again.
</P>
The first chapter is complete.
My Sina Weibo: www.weibo.com/wangyiyang