I have the following line of code in my model method.
subjectsinlist='['
subjectlist.subjects.each do |subject|
subjectsinlist=subjectsinlist+subject.subject_code+', '
end
subjectsinlist.chomp(', ')
subjectsinlist+="]"
An example of the strings to append are:
CPE205 CPE206 CPE301 CPE302 HW0210
I am expecting the results to hence be:
[CPE205, CPE206, CPE301, CPE302, HW0210]
But instead I am getting:
[CPE205, CPE206, CPE301, CPE302, HW0210, ]
The chomp
method does not seem to be working.
Any advice on why that happened would be appreciated.