Tip Sheet For Beginners

Tip Sheet For Beginners

Getting started

建立akelos项目

./akelos website_name

创建一个Controller和一个Model

./script/generate type name

“type”的位置是 controller 或者 model , “name” 由你决定. 你也可以试一试下面的方法

./script/generate scaffold

for information on creating scaffolds

Conventions

数据库中表的模式

复数形式,两个单词之间要用下划线代替空格,例如 steering_wheels

Akelos 自动处理 creation date/time 和 update date/time , 所以你不需要自己写代码了。 在一定范围之内处理时间和查询也许是非常敏捷的, 如果你使用了Akelos的约定,这些都来的简单。

使用习惯约定,如果你添加了一列名为”created_at”或者”updated_at”,akelos 为你自动处理这些字段而且如果你在migration中命名了一个字段,例如”posted_at”他会设置这个字段的类型和长度, 这个例子中类型是, datetime. 如果你使用了”created_on”他将只会使用”date”。

Model

单数形式,首字母大写,使用骆驼写法,像这样SteeringWheel

下面是数据的检验。

表与表之间的关系

Model文件中有这样的信息,显示如下,belongs_tohas_many并且akelos自动的显示了他们之间的联系,使用这样的字段像story表中的author_id

  • belongs_to - Story model 隶属于 Author.当一个数据表用belong_to连接到另一表的时候,你能关联到那个表的字段,通过把关系名附加到这个类名。例如,如果 product隶属于category,然后在处理product的视图中,你也能通过$Product→category→name获得category name。
  • has_many - 一个作者有很多小说

复数的事物。更应该注意– Akelos再一次的使用了单数和复数, 所以确定你包含了适当的‘s’。

Controller

习惯上是使用model名字的复数来定义Controller的名字的,例如 stories controller, authors controller

  • 说一下做什么,和在那里作。有像这样的逻辑”if post is not valid, send error about validation”。
  • 从model中为view准备变量。
    • 建立数据表的变量,可以在API中使用类似find('all')之类的命令。

View

Akelos的html是什么样的呢 ⇒ tpl

  • 使用Controller的变量并且打印他们
  • 从controller中获得变量,代替了这种方法$this→ symbol with $ ( Ex. $this→movies in bob_controller action submit ⇒ allows submit.tpl to access something called $movies )
  • scaffolding在视图清单中建立了edit, show, and delete的links。显示另一个字段来代替当前的,可以用这种方法
   <%= link_to product.name, :action => 'show', :id => product.id %>
 
tip-sheet-for-beginners_cn.txt · Last modified: 2008/10/08 07:01 by 221.239.198.119
 

The Akelos Framework was created by Bermi Ferrer and other contributors.
Potions of the code and documentation have been ported from Ruby on Rails.

The Akelos Framework is released under the LGPL license.

"Akelos", "Akelos Framework", and the Akelos logo are trademarks of Bermi Labs All rights reserved.

Wiki driven by DokuWiki