1

In a rails view, collection of items

<% @useful_types.each do |useful_type| %>

processes a number of operations

  <% @init = @valid_mos.first %>

These operations need to be held over as unique values in the same view to be used in furteh context. However I cannot fine the syntax to allow a processed string to generate an instance variable

<% @#{useful_type[2..-1]}_code = @init.code %>

is not allowed @#. Is there a succinct way to achieve this ?

1 Answer 1

3

Try with instance_variable_set:

<% instance_variable_set("@#{useful_type[2..-1]}_code", @init.code) %>
Sign up to request clarification or add additional context in comments.

1 Comment

For anyone stumbling onto this, there is the getter method to accompany that instance_variable_get . Neat.

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.