JSON variable in image_tag

I have some data in data.json like

{
    "articles": [
        {
            "poster": "my-image",
...

Then I load them with a loop

<% data.articles.articles.each do |article| %> <%= partial "partials/article" %> <% end %>

Then I would like to load an image in the “article” partial with the image_tag helper and “poster” as part of the src like:

<%= image_tag "posters/{article.poster}.jpg", :alt=>" ", :class=>"poster" %>

But I get "undefined local variable or method `article’ "
What’s the proper syntax ?

Found out I wasn’t passing the article variable.
Changed to:

<%= partial("partials/article", :locals => { :article => article}) %>

and used

<%= image_tag("posters/#{article.poster}.jpg", :alt=>" ", :class=>"poster") %>

1 Like