2

I'm trying to iterate through a regular array (not ActiveRecord), and render a partial using each element.

In my view (I'm using slim):

== render partial: "layouts/display_elements", collection: my_array

My partial (for now) only contains:

= "#{display_element}"

However, I'm getting the following error:

undefined local variable or method `display_element' for #<#<Class:0x007f7fe2e6ca58>:0x007f7fe51e0408>

Is this a limit of imposed by not using ActiveRecord? Do I have to resort to

= my_array.each do |e|

1 Answer 1

5

I am not very familiar with the slim-lang, but I think adding the :as option will work for you:

== render partial: "layouts/display_elements", collection: my_array, as: :display_element

This will allow you to access the collection my_array as the display_item local variable within your partial.

Sign up to request clarification or add additional context in comments.

Comments

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.