I have an array of hashes to store on a session variable recent visited items. I am able to iterate through each array item wihtout problem, but I am having a hard time to get an especific item out of the hash.
class AccountsController < ApplicationController
...
#Create new array if it does not exist
session[:recent_items] ||= Array.new
#insert an element on the first position
session[:recent_items].insert(0,{:type => "accounts", :id => @account.id, :name => @account.name })
#Remove duplicates
session[:recent_items] = session[:recent_items] & session[:recent_items]
#Grab only the first 5 elements from the array
session[:recent_items] = session[:recent_items].first(5)
...
end
Application View
<% session[:recent_items].each do |item| %>
<a href="/<%= item[:type] %>/<%= item[:id] %>"><%= item[:name] %></a>
<% end %>
On this last loop I am trying to generate a link for each last visited record. For example: -> 0.0.0.0/acccounts/1
And I get this error:
TypeError in Accounts#show
no implicit conversion of Symbol into Integer
UPDATE (12/13/2014)
If I only print the Array of Hashes, this is how it looks:
<li><%= session[:recent_items] %></li>

But I would like the "link format" mentioned above: -> 0.0.0.0/acccounts/1
itemto be an array, not a hash. What happens when you just<%= session[:recent_items] %>? Does it look like you expect?