Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails - Loop not printing the data in liquid template

Tags:

I have pulled some records from database that look like as following and are assigned a variable called users

[#
<User id: 53433, first_name: "Héctor", last_name: "Pinzon">,
<User id: 53434, first_name: "Héctor 2", last_name: "Pinzon 2">,
]

Inside the liquid I want to iterate over them via loop

{% for user in users %}
{{ user.first_name }}
{% endfor %}

When I get the email where the first_name is supposed to appear it prints out

 Liquid error: internal 
 Liquid error: internal

What am i doing wrong here? Why the data from users does not appear?

like image 444
Saadia Avatar asked Jul 25 '17 06:07

Saadia


1 Answers

Where ever you are passing users to your liquid template you need to change that to users.map(&:attributes) to get it in the correct format, we cant just pass the users object. After making this change then the following loop will render the data just fine.

{% for user in users %}
{{user.first_name }} {{user.last_name }}
{% endfor %}
like image 139
Shairyar Avatar answered Oct 13 '22 01:10

Shairyar