O'Reilly logo

Ruby by Example by Kevin C. Baird

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required