2

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.

1 Answer 1

2

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)
Sign up to request clarification or add additional context in comments.

2 Comments

what if I want to set it, for example <% $current_course.update_attributes(claimedreward1: true) %>
@M1xelated Updated answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.