Ben
Ben

Reputation: 712

Rails concatenation in each loop

I would like to use concatenation in rails loop :

I tried :

collection: "Service.active.#{service.type}"

collection: Service.active. + "#{service.type}"

<% services.each do |service| %>
   <div class="grid md:col-span-3">
      <%= f.association :services, as: :check_boxes, collection: "Service.active.#{service.type}", input_html: { multiple: false } %>
   </div>
<% end %>

Upvotes: 0

Views: 35

Answers (1)

Sebasti&#225;n Palma
Sebasti&#225;n Palma

Reputation: 33420

If what you want is to dynamically invoke a method on Service you can use Object#public_send. If the method isn't public you can use send;

Service.active.public_send(service.type)

Upvotes: 2

Related Questions