Tip Sheet For Beginners

Tip Sheet For Beginners

Getting started

Creating an Akelos project

./akelos website_name

Creating controllers and models

./script/generate type name

where “type” is controller or model and “name” is your choice. You can also try

./script/generate scaffold

for information on creating scaffolds

Conventions

Table (schema) in database

Plural, with underscores instead of spaces between words, like steering_wheels

Akelos handles creation date/time and update date/time out of the box, so there is no need to code it yourself. Handling dates and searching through ranges might be tricky, if you use the Akelos conventions this comes for free.

By convention if you add a column named “created_at” or “updated_at” it will handle those fields for you automatically and if you name a column in a migration like “posted_at” it will set the field type and length for you, in this case, datetime. If you use “created_on” it will use just “date”.

Model

Singular, first letter Capitalized, CamelCase for models like SteeringWheel

Validation of data is here.

Relationships between various tables

Model files have information in them which appears like belongs_to and has_many and reflects automatic connections made by Akelos, using fields like author_id in a story table

  • belongs_to - a Story model belongs_to an Author. When a table is linked to another table with belongs_to, you can refer to fields in that table by appending the relationship name to the class name. E.g., if product belongs_to category, then in a view that deals with product you can get the category name with $Product→category→name.
  • has_many - an Author has_many Stories

Plurality matters. Be very careful – Akelos does stuff with making this singular and plural again, so make sure you are including the appropriate number of s

Controller

Convention is to use the plural form of the model name when applicable, e.g. stories controller, authors controller

  • Says what to do and where to do it. Has logic like “if post is not valid, send error about validation”
  • Prepares variable for view from model
    • Create variable of tables using things like the find('all') command in the API

View

How things look - Akelos in html ⇒ tpl

  • Uses variables in Controller and prints them
  • Get variable from controller replacing $this→ symbol with $ ( Ex. $this→movies in bob_controller action submit ⇒ allows submit.tpl to access something called $movies )
  • The scaffolding creates edit, show, and delete links in list views. To replace the text 'show' with another field in the list view, do this
   <%= link_to product.name, :action => 'show', :id => product.id %>
 
tip-sheet-for-beginners.txt · Last modified: 2008/02/04 14:59 by thijs