How can I improve this if in ruby?
Original if:
status = 'None available',
css_class = 'grey'
if pending_final > 0
status = 'Pending'
css_class = 'red'
elsif requested_final == 0 && request.granted
status = 'Granted'
css_class = 'green'
elsif requested_final == 0 && request.granted == false
status = 'Not requested'
css_class = 'red'
end
I was trying to refactor like this:
status, css_class = if pending_final > 0
'Pending', 'red'
elsif requested_final == 0 && request.granted
'Granted', 'green'
# and so on...
else
'None available', 'grey'
end
But then I have a syntax error in the "," commas.
Aucun commentaire:
Enregistrer un commentaire