Dissecting the Application

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.

Dissecting the Photo Model

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 ...

Get Ruby by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.