Ror study Note 1

Source: Internet
Author: User

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

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.