Getter and Setter with non DB property

Hi,

I can’t find how do i created a getter and setter property for a non db
property. what i have done isnt working, i have a cnt mass assign error.

Here is what i’ve done:
attr_accessor :creator_is_participant

def creator_is_participant
@participe
end

def creator_is_participant=(participe)
if participe == true
@participe = true
else
@participe = false
end
end

Greg

On Apr 18, 12:49 pm, Greg Ma [email protected] wrote:

Hi,

I can’t find how do i created a getter and setter property for a non db
property. what i have done isnt working, i have a cnt mass assign error.

The mass assignment error is probably not related to this (at least
not what you have shown)

Here is what i’ve done:
attr_accessor :creator_is_participant

What this does is create a getter and setter method of that name that
stores its data in @creator_is_participant - if you’re going to
redefine both of those methods then you don’t need that

def creator_is_participant=(participe)
if participe == true
@participe = true
else
@participe = false
end
end

This may have unintended consequences further down the line because it
puts you at odds with what the ruby world considers to be true/false:
nil and false are false, everything else has the truth value true

Fred

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs