2016-07-13 32 views
1

我試圖按照創建Evernote克隆的教程進行操作,但第5行中的這一部分遇到了麻煩,應該將其鏈接迴文檔。當我嘗試運行它,它讓我在文件#指數類型錯誤和「文件中的隱式轉換成整數」:haml中的Rails和href

.wrapper_with_padding 
    #docs.clearfix 
     -unless @docs.blank? 
      - @docs.each do |doc| 
       %a{href: (url_for[doc])} 
        .doc 
         %p.title= link_to doc.title 
         %p.date= time_ago_in_words(doc.created_at) 
         %p.content= truncate(doc.content, length:50) 
     -else 
      %h2 Create Doc! 
      %p Start Creating Documents and Organizing Your Life! 
      %button= link_to "Create Doc", new_doc_path 
+1

使用to_s方法在字符串轉換 – uzaif

回答

2

您需要更改線路:5 -

%a{href: (url_for(doc))} 


%a{href: (url_for[doc])} # this will give you following error 
#=> ActionView::Template::Error (can't convert Doc into Integer): 

參考url_for

0

url_for[doc]應該url_for(doc)