3
我想做一個簡單的博客露營,就像野營的例子,只有我想用視圖而不是markaby使用haml。我想使用_post.html.haml部分來渲染帖子,但我有一種感覺,我可能會以錯誤的方式去做。渲染一個部分與露營和哈姆
Blog.rb
require 'camping'
Camping.goes :Blog
Blogtitle = "My Blog"
module Blog
# Path to where you want to store the templates
set :views, File.dirname(__FILE__) + '/views'
module Blog::Models
class Post < Base; belongs_to :user; end
class Comment < Base; belongs_to :user; end
class User < Base; end
end
module Blog::Controllers
class Index
def get
@posts = Post.find :all
render :index
end
end
end
end
視圖/ index.html.haml
!!!
%html
%head
%meta{'http-equiv' => 'Content-Type', :content => 'text/html', :charset => 'UTF-8' }/
%title=Blogtitle
%body=render @posts
視圖/ _post.html.haml
%h2=post.title
%p=post.html_body
錯誤
NoMethodError at/
undefined method `to_sym' for #<Array:0xb6e426d4>
Ruby (eval): in lookup, line 12
Web GET 0.0.0.0/
Traceback (innermost first)
(eval): in lookup
(eval): in render
/home/tony/src/blog/views/index.html.haml: in evaluate_source
%body=render @posts
的` meta標籤已經在[self-closing tags]列表中(http://haml-lang.com/docs/yardoc/file.HAML_REFERENCE.html#selfclosing_tags_),所以你不需要尾隨的`/` ;如果你刪除它,它有幫助嗎? – Phrogz 2011-01-07 21:03:25
不,問題出在`%body = render @ posts`行,但是謝謝,我不知道`/`是不必要的。 – freedrull 2011-01-07 23:49:24