Format of a string, array or hash

Hello there,
I do not know if my topic is right so I'll explain the problem :

I have a Project model :

class Project < ActiveRecord::Base
  has_and_belongs_to_many :services

In my views. I would like to list the services in the title of the page.

I did :
<% for service in %-><%= service.name_fr.downcase -%>,
<% end -%>.

The problem is with the listing itself, it puts this :
{} required {service.name1}, {service.name2},

There is a problem with the last comma. It looks awful from a web
developer view.

I would like :
{} required {service.name1}, {service.name2} and

Notice the attribute «and» and «dot» at the end

How do you call that thing I am looking for?
Is there a way to do it like the second exemple?

Thx a lot for your time and help.


Something like this should work: {|service|}.join(", ").gsub(/,
([A-Za-z]+)$/,' and \1.')

:: though you might need to tweak that regex, depending on what's
in a service name...


Sweet, didn't know that one. Let's add the period, though:{|s|}.to_sentence.concat(".")

Et voila, another good day's work :slight_smile:

Hello Hassan and Eric,
Outstanding! Thanks a lot, It works perfectly.