《Agile Web Development with Rails》读书笔记(二)

原创 2007年09月19日 15:06:00

Instant Gratification

After the Rails environment has been established, I write a simple application to verify we have got Rails snugly installed on my machine.

        I.              Create a new project

Rails application is a bunch of Ruby source code, but does a lot of magic behind the curtain to minimum the explicit configuration.

I’ll use a new command-line tool rails to create my first project.

To create the first Rails application, pop open a shell window, navigate to a place in the file system where I want to create the application directory structure.

  work>rails demo

This command creates a bunch of files and subdirectories, you can cd demo to have a look at it.

Two directories will be used in this example:

app: the kernel of MVC, put application code files here.

script: contain some useful utility scripts.

In order to see the result of create application, I start the stand-alone develop web server:

  work>ruby script/server

note: this command will hang up the command shell, so open another shell window, change to the application directory to run the above command.


The service start on port 3000. I access the application using the URL

the work of “create new application” is finished when I see the “welcome aboard” page in the browser.

Now, let’s write some content for this application.

     II.              Hello Rails!

Before I write some content for the application, first I introduce some concept.

The Architecture of Rails:

Rails accept a request from browser, decodes the request to find the controller, and call the action method in that controller. The controller then invoke a particular view to display the result to the user.

Rails and Request URLs

Like other web application, Rails application appears to its users to be associate with a URL.

I’ll take a URL as an example to explain it:

Rails uses the path to determine the name of the controller to use and the name of the action to invoke in that controller.

My First Action

Ok, now let’s write some content for our application.

Followed the discussion in the previous section, the hello action means create a method in the class SayController.

The controller’s job is to set up things so that the view knows what to display.


class SayController > ApplicationController

   def hello






      <title>Hello, Rails!</title>



      <h1>Hello from Rails!</h1>



Save these two files, and refresh the browser, then you should see my friendly greeting.

Agile Web Development with Rails

版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章原始出版、作者信息和本声明。否则将追究法律责任。http://blog.csdn.net/topmvp - topmvpRails is ...
  • topmvp
  • topmvp
  • 2008年08月18日 22:52
  • 323

《Agile Web Development with Rails》读书笔记(四)

The Depot ApplicationI’ll take the creating a depot application of books for maintaining and buying ...
  • zqho
  • zqho
  • 2007年09月21日 14:44
  • 522

《Agile Web Development with Rails》读书笔记(一)

        I.              My way of RailsWorking as an embedded system developer, I never know much ab...
  • zqho
  • zqho
  • 2007年09月19日 10:20
  • 410

《Agile Web Development with Rails》读书笔记(三)

Make Dynamic PagesIn order to get dynamic pages, I need to embed some ruby code into the *.rhtml in ...
  • zqho
  • zqho
  • 2007年09月19日 17:13
  • 365

敏捷开发(Agile Development)简介

      敏捷开发(agile development)是一种以人为核心、迭代、循序渐进的开发方法。在敏捷开发中,软件项目的构建被切分成多个子项目,各个子项目的成果都经过测试,具备集成和可运行的特征...
  • wayne_ran
  • wayne_ran
  • 2007年05月08日 20:16
  • 4305

Agile Web Development with Rails 翻译(二)

Agile Web Development with Rails 翻译(二)第二章 Rails应用程序的体系 在你构造你的Web应用程序时,Rails引进了一些合理的约束。令人惊讶的是这些约束反而使创...
  • ajiva
  • ajiva
  • 2006年09月11日 14:33
  • 1995

Agile Web Development with Rails 翻译

  • qiqiy
  • qiqiy
  • 2008年09月20日 22:47
  • 249

《Agile Software Development: Principles, Patterns, and Practices》

  • saintxzm
  • saintxzm
  • 2007年07月26日 17:18
  • 1709

Agile Web Development with Rails 翻译(十八)

Agile Web Development with Rails 翻译(十八) 这里,唯一有趣的是和选择列表有关的代码。我们已经假定有效付款选项清单是Order model的一个属性--它将是mode...
  • ajiva
  • ajiva
  • 2006年09月11日 15:04
  • 2231

Agile Web Development with Rails 翻译(十七)

Agile Web Development with Rails 翻译(十七)第九章 任务 D: 结算!   迄今为止,我们已经建立了一个基本的产品管理系统,我们实现一个分类目录,并有一个很好看的商店...
  • ajiva
  • ajiva
  • 2006年09月11日 15:01
  • 2481
您举报文章:《Agile Web Development with Rails》读书笔记(二)