Reputation: 411
Why when you iterate through a serialized JSON hash but spits out that the class is nil
?
<% @test.yo.keys.each do |key| %>
<%= key %>
<% end %>
class Test < ActiveRecord::Base
belongs_to :city
serialize :yo, JSON
end
Upvotes: 0
Views: 5343
Reputation: 5370
it's saying that yo is nil for @test. you need to check yo for nil before you call a method against it :
<% if [email protected]? %>
<% @test.yo.keys.each do |key| %>
<%= key %>
<% end %>
<% end %>
you can probably find a better place to put your check, but this gives you an idea of how to fix it
Upvotes: 1