Commit 18643470172db6f1ee7f2010867963752335ad43

Retrieved @posts inside Posts#index, created a shared posts template, using partials we render this template for each post.

Commit diff

app/controllers/posts.rb

 
11class Posts < Application
2
2
33 def index
4 @posts = Post.find( :all, :order => "created_at DESC" )
45 render
56 end
6
7
78end
toggle raw diff

app/views/posts/index.html.erb

 
1You're in index of the Posts
1<h1>Welcome to Slapp</h1>
2<h2>A simple chat wall</h2>
3
4<p>Recent Posts:</p>
5<div id="posts" class="container">
6 <%= partial( "/shared/post", :with => @posts ) %>
7</div>
toggle raw diff

app/views/shared/_post.html.erb

 
1<div id="<%= post.id %>" class="post">
2 <p class="body"><%= h( post.body ) %></p>
3 <p class="created"><%= relative_date( post.created_at ) %></p>
4</div>
toggle raw diff

log/merb_test.log

 
4141 ~ Compiling routes...
4242 ~ Using 'share-nothing' cookie sessions (4kb limit per client)
4343 ~ {:action_time=>0.023912, :before_filters_time=>1.6e-05, :after_filters_time=>9.0e-06}
44 ~ Loaded TEST Environment...
45 ~ loading gem 'merb_activerecord' from ...
46 ~ loading gem 'merb_helpers' from ...
47 ~ loading gem 'activerecord' from ...
48 ~ Connecting to database...
49 ~ Compiling routes...
50 ~ Using 'share-nothing' cookie sessions (4kb limit per client)
51 ~ SQL (0.000231) SET NAMES 'utf8'
52 ~ SQL (0.000099) SET SQL_AUTO_IS_NULL=0
53 ~ Post Load (0.000522) SELECT * FROM `posts` ORDER BY created_at DESC
54 ~ {:action_time=>0.045228, :before_filters_time=>1.4e-05, :after_filters_time=>1.0e-05}
55 ~ Loaded TEST Environment...
56 ~ loading gem 'merb_activerecord' from ...
57 ~ loading gem 'merb_helpers' from ...
58 ~ loading gem 'activerecord' from ...
59 ~ Connecting to database...
60 ~ Compiling routes...
61 ~ Using 'share-nothing' cookie sessions (4kb limit per client)
62 ~ SQL (0.000248) SET NAMES 'utf8'
63 ~ SQL (0.000098) SET SQL_AUTO_IS_NULL=0
64 ~ Post Load (0.000383) SELECT * FROM `posts` ORDER BY created_at DESC
65 ~ {:action_time=>0.045942, :before_filters_time=>1.4e-05, :after_filters_time=>1.1e-05}
66 ~ Post Columns (0.002168) SHOW FIELDS FROM `posts`
toggle raw diff