mercredi 1 février 2017

Ruby on Rails: Is it possible to display two variables against with collection_check_boxes?

In my RoR application I am displaying a checkboxes for a user's to select their contacts. This is done through the following line of code:

<%= f.collection_check_boxes :contact_ids, Contact.where(user_id: session[:user_id]), :id, :firstname, { prompt: "firstname" } %>

This only display the contacts' firstname, is it possible to display both firstname and surname?

I have tried the following, but they have not worked.

<%= f.collection_check_boxes :contact_ids, Contact.where(user_id: session[:user_id]), :id, { :firstname & " " & :surname }, { prompt: "firstname" } %>
<%= f.collection_check_boxes :contact_ids, Contact.where(user_id: session[:user_id]), :id, { :firstname :surname }, { prompt: "firstname" } %>
<%= f.collection_check_boxes :contact_ids, Contact.where(user_id: session[:user_id]), :id, :firstname :surname, { prompt: "firstname" } %>

Is this possible?

Aucun commentaire:

Enregistrer un commentaire