June 2007
Intermediate to advanced
294 pages
8h 6m
English
Now that we have created the basic skeleton of our application, let’s examine how it works. Think of this section as similar to the sections The Code or How It Works in previous chapters.
Our photo album app has one basic piece of data, represented in a Model called Photo. Let’s add some code to what’s already there and explore what it does. Edit app/models/photo.rb to match the following:
class Photo < ActiveRecord::Base =begin explain Closely follows Object-Relational Model, each instance is also a record in the table called 'photos'. =end ❶ def next_id() return Photo.minimum(:id) if last_id? next_id = @attributes['id'].to_i.succ next_id.succ! until Photo.find(next_id) next_id.to_s end ❷ def ...
Read now
Unlock full access