I am trying to get a dropdown list of projects organized according to the owner name. For doing this I am using SimpleForm and the grouped_select method. The issue is that for now it is a hash that is send back to the dropdown list and not the name of the project. How can I get solely the name of the project within this hash ?
This is how I define my collection
def option_clients_projects
unless self.contractor.nil?
opt_clients = self.contractor.construction_projects.map{ |cp| {:construction_project => cp.name, :client_name => cp.client.name} }
opt_clients << {:construction_project =>"Add a new project", :client_name => ""}
opt_clients
end
end
//This is what i get out this method//
[{:construction_project=>"Toilette fr", :client_name=>"Martine depouhon"}, {:construction_project=>"démolition Chateau", :client_name=>"Carla"}]
>
This is my input as grouped_select within my SimpleForm
<%= f.input :construction_project_id, collection: current_user.option_clients_projects.group_by{ |d| d[:client_name] }, as: :grouped_select, group_method: :last, group_label_method: :first %>
//The result of the group_by operation//
{"Martine depouhon"=>[{:construction_project=>"Toilette fr", :client_name=>"Martine depouhon"}], "Carla "=>[{:construction_project=>"démolition Chateau 2 2", :client_name=>"Carla "}]}
>
group_method - The name of a method which, when called on a member of collection, returns an array of child objects representing the tags.