《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

  http://127.0.0.1:3000

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.

work/demo/app/controllers/say_controller.rb

class SayController > ApplicationController

   def hello

   end

end

work/demo/app/views/say/hello.rhtml

<html>

   <head>

      <title>Hello, Rails!</title>

   </head>

   <body>

      <h1>Hello from Rails!</h1>

   </body>

</html>

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

相关文章推荐

Mastering Web Application Development with AngularJS-Packt 2013 读书笔记(不错的好书!)

Angular Zen Batarang Batarang is a Chrome developer tool extension for inspecting the AngularJ...
  • cteng
  • cteng
  • 2017年08月03日 14:29
  • 344

《Expert Cube Development with Microsoft SQL Server 2008 Analysis Services》读书笔记第九章:保护Cube(一)

SQL Server 2008中SQL应用系列及BI学习笔记系列--目录索引   对Analysis Services Cube而言,安全,是一个非常重要的问题。在某种形式的安全要求下,Cube中的数...

Agile Web Development with Rails 4

  • 2016年06月01日 11:38
  • 9.45MB
  • 下载

《Designing with Web Standard(Third Edition)》/《网页重构》读书笔记

---------------------------------------读书笔记·转载请注明---------------------------------------   学习前...
  • Hookc
  • Hookc
  • 2013年11月04日 00:54
  • 881

agile web development with rails2代码

  • 2008年08月05日 14:32
  • 1.83MB
  • 下载

《Agile Java读书笔记》 第一章

由于我之前学过C++和C,C#也稍微有一点了解,所以Java的语法对我来说不算太难,读Agile Java这本书仅仅是为了从细节学习学习Java语法,另外,更重要的是学习学习TDD(Test-Driv...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:《Agile Web Development with Rails》读书笔记(二)
举报原因:
原因补充:

(最多只允许输入30个字)