Reputation: 712
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
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