O'Reilly logo

RubyMotion by Clay Allsopp

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

Writing Basic Models

Unlike controllers and views, there’s no default superclass that models inherit from; they’re just plain-old Ruby objects. We can use the standard attr_accessor, reader, and writer functions to declare getter and setter methods, which sometimes are all you need.

Many apps have users and profiles, so let’s work through a portion of that sort of app and use some nice models. Let’s create a new project (such as motion create UserProfile) and two subdirectories within ./app: models and controllers. We’re not only going to cover models; we’re going to keep building on what we already know.

Our app will let us create, view, and edit users. Since we’re doing an awful lot of work with users, this sounds like a good place to ...

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