M1xelated
M1xelated

Reputation: 169

Rails add variable to another variable

I am a bit stuck. And I know there should be an easy solution. So I have this line of code:

  <% if $current_course.claimedreward1 == false%>

and a variable

$number = 1 

I am trying to get the 1 replaced by $number

I tried

<% if $current_course.claimedreward+$number == false%>

There must be a super simple way to do this. I found #{} but it only seems to work for strings. I am a bit lost.

Upvotes: 2

Views: 53

Answers (1)

Matt
Matt

Reputation: 14048

You could use send to build a method/attribute name programatically:

<% if $current_course.send("claimedreward#{$number}") == false%>

update_attribute("claimedreward#{$number}", true)
update_attributes("claimedreward#{$number}" => true)

Upvotes: 2

Related Questions