What I have is a dynamically created list thats built off a “each” loop. Where every variable it tacks on it also adds “,” to that string, basically making a CSV style list. What I want to do is remove the last character. Because at the end of the run through the loop there is the extra “,” at the end.
I am trying to find the equivalent to this from PHP
echo substr($str,0,($len-1));
based on the Rails For PHP site it says do something like
puts @avaliable_list.slice(0, 1)
and
puts @avaliable_list[0, 1]
which either rails version leaves me with only the very first character of the string, does not remove the last piece like I want it to. The Rails for PHP site would have me believe that 0 represents the end of the string, and the 1 would be the total char’s I want to remove from said string. Instead it does the opposite.
You should
jointhe array instead of usingeach.