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

原创 2007年09月19日 17:13:00

Make Dynamic Pages

In order to get dynamic pages, I need to embed some ruby code into the *.rhtml in views.

First, I introduce some symbols in *.rhtml.

<%= %> : content between <%= %> is interpreted as ruby code and executed. The result of that execution is converted into a string, and that value is substituted into the file in place of the <%= %> sequence.

<% %> : mostly the same as <%= %>, except the result did not display—never converted into a string and never substituted into the file.

<%= -%> : tell rails to remove any new line that follows from the output.

h( ) : prevent the special characters from grabling the browser display—they’ll escape as html entities.

Now, we create a page to display the current time when you refresh the page.

In order to accord with the spirit of MVC, first we save the current time in a variable in the controller’s method, then we use the variable to display the current time in views.


class SayController > ApplicationController

   def hello

      @time = Time.now






      <title>Hello, Rails!</title>



      <h1>Hello from Rails!</h1>


      It is now <%= @time %>




Save this file, you’ll see the current time when you refresh the page.

Our story illustrates convention over configuration, one of the fundamental parts of the philosophy of Rails.


Link Pages Together

There are two way to link pages together.

<a href =  “/say/goodbye”>Goodbye</a>

Rails use a convention to parse the URL into a target controller and an action within that controller. Here say is controller, goodbye is the action in say.

Flaw: the hyperlink path is relative, if we move the application to a different place on the web server, the URL would no longer be valid.


:action : Ruby symbol, you can think of the colon as meaning the thing named…, so :action means the thing named action, the => “goodbye” associate the string goodbye with the name action.


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
  • 347

Agile Web Development with Rails 4

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

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

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

《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》读书笔记(三)