我正在尝试使用露营制作一个简单的博客,就像露营附带的示例一样,只是我想使用haml而不是markaby作为视图。我想使用 _post.html.haml 部分渲染帖子,但我觉得我可能会以错误的方式进行处理。
博客.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