Rails 和 haml 中的 href
Rails and href in haml
我正在尝试按照创建 Evernote 克隆的教程进行操作,但是 运行 在第 5 行的这一部分应该 link 返回文档时遇到了麻烦。当我尝试 运行 时,它在 Docs#index 和 'no implicit conversion of Doc into Integer':
中给我一个 TypeError
.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
url_for[doc]
应该是 url_for(doc)
您需要将 line: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
我正在尝试按照创建 Evernote 克隆的教程进行操作,但是 运行 在第 5 行的这一部分应该 link 返回文档时遇到了麻烦。当我尝试 运行 时,它在 Docs#index 和 'no implicit conversion of Doc into Integer':
中给我一个 TypeError.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
url_for[doc]
应该是 url_for(doc)
您需要将 line: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