Getting last item in list

Hi,

I am a noob to development beyond front-end html/css. I am pulling info from a yaml data file, but am needing to apply a different selector to the last item of the three in my file.

Currently I have this:

%h1 About
- data.services.services.each do |service|
   %div.m-service
      %h2= service

Any help would be great! Thank you!

Hello,

I am sure there are other ways but the easiest way you can go about this using ruby is the following:

%h1 About
- last = data.services.services.last
- data.services.services.each do |service|
  - if service == last
    %div.m2-service
      %h2= service
  - else
    %div.m-service
      %h2= service

This code takes for granted that each element of the ‘data.services.services’ array is unique. If that’s not the case (for any reason), I’d remove last item from the array save it to a variable and use it when and where I need to.

Regards

Do you really need a special class for that? Can’t you just use :last-of-type ( http://www.w3schools.com/cssref/sel_last-of-type.asp ) or :last-child?

But, to answer your actual question

Thank you both for your time an answers!

@tommysundstrom you have a very valid point with the CSS! I did not consider that. I also was able to take care of it via putting the grid cols within a row in Neat’s grid system.

Thanks again for your patience!