在我的视图中显示原始哈希

时间:2017-11-01 02:51:50

标签: ruby-on-rails

我的控制器在index中有一个哈希值。

suggestions_controller.rb

class SuggestionsController < ApplicationController
    def index
        @mercs = {
            'Proxy' => './mercs/proxy.png',
            'Arty' => './mercs/arty.png',
            'Aura' => './mercs/aura.png'
        }
    end
end

当我将其转移到我的视图时,

index.html.erb

<div class="merc-list">
    <%= @mercs.each do |merc, img| %>
        <div class="merc">
        </div>
    <% end %>
</div>

我的视图显示原始哈希:

Problem

我也尝试使用常规数组(没有哈希),并在我的视图中显示原始数组。

1 个答案:

答案 0 :(得分:1)

    <%= @mercs.each do |merc, img| %>

应该是

    <% @mercs.each do |merc, img| %>