Kieran Klaassen
Kieran Klaassen

Reputation: 2202

Ruby dynamic symbol in each block

How can I make my symbol dynamic with an incremental number like this:

@order.products.each do |product,num|
    = f.input :aanbod+num.to_s

Upvotes: 13

Views: 5161

Answers (2)

maček
maček

Reputation: 77786

This form is equivalent to "aanbod#{num}".to_sym and more concise:

= f.input :"aanbod#{num}"

Upvotes: 24

Shadwell
Shadwell

Reputation: 34774

= f.input ("aanbod" + num.to_s).to_sym

or

= f.input "aanbod#{num}".to_sym

Upvotes: 6

Related Questions