Hi,
I’ve got a checkbox on my form that the user checks to say whether
they want to receive a newsletter or not. It looks like this:
The subscribe_to_newsletter attribute is not in the database, just a
attr_accessor :subscribe_to_newsletter.
I need to write a method to show whether this has been checked or not.
I believe that if the attribute was in the database, then a question
mark method such as subscribe_to_newsletter? would automatically
written for me to return true or false. But, it’s not in the database.
I’ve written this so far, which works, but is there a better way which
I am missing?
def receive_newsletter?
subscribe_to_newsletter == “1” ? true : false
end
Thanks,
Jord