2016-11-18 46 views
1

我不知道爲什麼我收到此錯誤。必須有一個錯誤,但不幸的是我目前找不到它。引腳中的NoMethodError#索引,未定義的方法`stringify_keys

Index.html.erb:

<div id="pins" class="transitions-enabled"> 
    <% @pins.each do |pin| %> 
    <div class="box panel panel-default"> 
     <%= link_to image_tag(pin.image.url(:medium)), pin %> 
     <div class="panel-body"> 
     <p><%= pin.description %></p> 
     <p><strong><%= pin.user.email if pin.user %></strong><p> 

     <% if pin.user == current_user %> 
      <div class="actions"> 
      <%= link_to edit_pin_path(pin) do %> 
      <span class="glyphicon glyphicon-edit"></span> 
      Edit 
      <% end %> 
      <%= link_to 'Delete', pin, method: :delete, data: { confirm: 'Are you sure?' } do %> 
      <span class="glyphicon glyphicon-trash"></span> 
      Delete 
      <% end %> 
      </div> 
     <% end %> 
     </div> 
    </div> 
    <% end %> 
</div> 
在我的控制檯

,錯誤:

ActionView::Template::Error (undefined method `stringify_keys' for #<Pin:0x007f568d39a428>): 
    12:    <span class="glyphicon glyphicon-edit"></span> 
    13:    Edit 
    14:    <% end %> 
    15:    <%= link_to 'Delete', pin, method: :delete, data: { confirm: 'Are you sure?' } do %> 
    16:    <span class="glyphicon glyphicon-trash"></span> 
    17:    Delete 
    18:    <% end %> 

,如果我編輯`

<%= link_to 'Delete', pin, method: :delete, data: { confirm: 'Are you sure?' } do %>` 

<%= link_to pin, method: :delete, data: { confirm: 'Are you sure?' } do %> 
似乎

它的工作原理和頁面加載,但創建了其他問題,我沒有以前沒有像在用戶登錄時加載'刪除'選項'我的'別針'。但是,他們出現時,沒有人登錄後:/

+0

您是否在控制器中發生錯誤?你能粘貼你得到的完整錯誤嗎? –

+0

可能的重複[NoMethodError在汽車#索引](http://stackoverflow.com/questions/6034106/nomethoderror-in-carindex) –

+0

@Benjamins尋求調試幫助(「爲什麼不是這個代碼工作?」)的問題包括所需的行爲,特定的問題或錯誤以及在問題本身中重現問題所需的最短代碼。沒有明確問題陳述的問題對其他讀者無益。 –

回答

0

以後向鏈接寫入link_to時,它不需要鏈接的文本內容。

<%= link_to pin, method: :delete, data: { confirm: 'Are you sure?' } do %> 
    <span class="glyphicon glyphicon-trash"></span> 
    Delete 
<% end %> 

在你的代碼它試圖解析引腳選項部分link_to 'delete', pin, ... do經過哈希

至於你刪除按鈕只顯示了當有人未簽名的時候,我最好的猜測會是你的pin.usernil,當沒有人登錄時匹配。所以也許更新的條件是if current_user.present? && pin.user == current_user