简体   繁体   中英

How can I display hash data?

<% @user.dids.each_with_index{ |did, i| %>
  <li><%=h @user.dids %></li>
<% } %>

result to display

#<Did:0x7fc4c55f4bf0>#<Did:0x7fc4c55f4ba0>#
<Did:0x7fc4c55f4b50>#<Did:0x7fc4c55f4b00>#
<Did:0x7fc4c55f4a88>#<Did:0x7fc4c55f4a10>#
<Did:0x7fc4c55f49c0>#<Did:0x7fc4c55f4970>

I almost sleep and did not think, tell me somebody how to display the hash data

您可以在rails中使用debug函数

<%= debug @user %>

First off, your loop is a bit strange. It seems to me that you should have

<% @user.dids.each_with_index{ |did, i| %>
  <li><%=h did %></li>
<% } %>

In your version, you are printing the entire @user.dids with each iteration.

Also, how is the class Did defined? If you are in Rails and Did is an ActiveRecord model, you should have the .to_json method available to you (options and info here ):

<% @user.dids.each_with_index{ |did, i| %>
  <li><%=h did.to_json %></li>
<% } %>

OK I sleep so correctly

<% @user.dids.each_with_index{ |did, i| %>
  <li><%= did.did %></li>
<% } %>

Thank you for helping colleagues

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM