haml中的Rails和href

时间:2016-07-13 13:08:08

标签: ruby-on-rails ruby haml

我正在尝试按照创建Evernote克隆的教程进行操作,但是第5行的这一部分遇到了麻烦,应该链接回文档。当我尝试运行它时,它在Docs #index中给出了一个TypeError,并且没有将Doc隐式转换为整数':

.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

2 个答案:

答案 0 :(得分: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

答案 1 :(得分:0)

url_for[doc]应为url_for(doc)