0

I upload documents and then on my admin home page I display all the documents like so:

<% @document.each do |document|%> 
     <p><%= link_to document.name, document.contract_url.to_s%></p>
<%end%>

In my user's home page I render the documents that belong to specific users like so:

<%= current_user.documents.each do |document|%>
    <p><%= link_to document.name, document.contract_url.to_s%></p>
<%end%>

But in the user's home page I get this array after my link.

Document Name (link)
[#<Document id: 2, name: "Document Name", user_id: 2, contract: "contract_name.pdf", created_at: "2012-10-03 13:12:40", updated_at: "2012-10-03 13:35:35">] 

I do not get this array in my admin panel. I just get the "Document Name" link. Does anyone know what could be causing this?

Benamir
  • 1,107
  • 2
  • 11
  • 24

1 Answers1

2
[#<Document id: 2, name: "Document Name", user_id: 2, contract: "contract_name.pdf", created_at: "2012-10-03 13:12:40", updated_at: "2012-10-03 13:35:35">]

is not a hash, it's an Array. It's an Array with a single class instance of your Document model.

#<Document id: 2, name: "Document Name", user_id: 2, contract: "contract_name.pdf", created_at: "2012-10-03 13:12:40", updated_at: "2012-10-03 13:35:35">

This is the return value (String representation of a model) of the following (try it in rails console to see)

Document.find(2).to_s

In your code you have

<%= current_user.documents.each do |document|%>

You are printing the current_user.documents collection. This is the same as you doing

puts current_user.documents

in rails console. Get rid of the =.

<% current_user.documents.each do |document|%>
deefour
  • 34,974
  • 7
  • 97
  • 90