I have a enum and two Constant
enum status: { draft: 0, published: 1 }
I_CODE = 23
J_CODE = 24
I have a method in that I have to check status is draft then in database I have to save value 23 and if status is published I have to save 24 in database. when I am trying to compare like status == draft? then it is not working.
def status=(status)
self[:status] =
if status.blank?
nil
elsif status == 0
I_CODE
elsif status == 1
M_CODE
end
end
But for showing in UI I want to show if status == draft then it should show draft.
def status
if status == 0
Draft
elsif status == 1
Published
else
"----"
end
end
Could someone please help me.
Aucun commentaire:
Enregistrer un commentaire