From the course: Ruby on Rails 6 Essential Training: Models and Associations

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Non-database attributes

Non-database attributes - Ruby on Rails Tutorial

From the course: Ruby on Rails 6 Essential Training: Models and Associations

Start my 1-month free trial

Non-database attributes

- [Narrator] In this chapter, we're going to be talking about, how to make our models smarter. And we're going to start by talking about non-database attributes. In Ruby just basic Ruby, not Ruby on Rails, We can create new attributes in an instance, by using a couple of different methods. They're shortened, but we can read them as attribute reader, attribute writer, and the combination of the two attribute accessor. Hopefully you remember these and you remember what they do. If inside of a Ruby class, we call attribute accessor. And in this case I'm using status with it. It has the exact same effect. It has the exact same effect, as if we had defined two methods in that class one, that's a reader method for status and one that's a writer method for status. And those allow us to read and write values to the instance variables status. Now we do this a lot when we're programming in pure Ruby, but in Ruby on Rails…

Contents