开发者

rendering a partial with camping and haml

I'm trying to make a simple blog with camping, like the example that comes with camping, only I want to use haml for the views instead of markaby. I want to render the posts using a _post.html.haml partial, but I have a feeling I may be going about it the wrong way.

Blog.rb

require 'camping'

Camping.goes :Blog

Blogtitle = "My Blog"

module Blog
  # Path to where you want to store the templat开发者_StackOverflowes
  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

views/index.html.haml

!!!
%html
%head
%meta{'http-equiv' => 'Content-Type', :content => 'text/html', :charset => 'UTF-8' }/
%title=Blogtitle
%body=render @posts

views/_post.html.haml

%h2=post.title
%p=post.html_body

error

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


First of all, to render a partial, you'll have to do something like this:

render :_post, :locals => { :post => post }

If you wish to render all the posts, just use a loop:

%body
  - @posts.each do |post|
    = render :_post, :locals => { :post => post }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜