gr8scott06
gr8scott06

Reputation: 931

Rails set attribute with looping one-liner

I want to define a Model attribute.

Can you do this in one line?

d = []
item.xpath("feature").each {|i| d << i.text}
product.description = d.join(", ")

Upvotes: 0

Views: 36

Answers (1)

Patrick Oscity
Patrick Oscity

Reputation: 54704

Yes.

product.description = item.xpath("feature").map(&:text).join(", ")

Upvotes: 4

Related Questions