Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

updated the views and templates

  • Loading branch information...
commit 9d66b2c89f82871195f0ef20788210f1a9907784 1 parent efa0607
@foca authored
View
19 app/templates/posts/index.html.mustache
@@ -1,6 +1,15 @@
-{{# posts }}
- <h2>{{ title }}</h2>
- {{ body }}
-{{/ posts }}
+{{# posts? }}
+<ol>
+ {{# posts }}
+ <li>
+ <h2><a href="{{ url }}">{{ title }}</a></h2>
+ {{{ body }}}
+ <p><a href="{{ url }}">Continue reading…</a></p>
+ </li>
+ {{/ posts }}
+</ol>
+{{/ posts? }}
-<div><%= link_to 'New post', new_post_path %></div>
+<p class="admin">
+ <a href="{{ new_post_path }}">Write a new post</a>
+</p>
View
2  app/templates/posts/post.html.mustache
@@ -1,2 +0,0 @@
-<h2>{{ title }}</h2>
-{{ body }}
View
23 app/templates/posts/show.html.mustache
@@ -1,18 +1,15 @@
-<h2>{{{ title }}}</h2>
+<h2><a href="{{ url }}">{{ title }}</a></h2>
{{{ body }}}
-<div id="manage">
- {{{ edit_link }}}
+<div id="admin">
+ <a href="{{ edit_path }}">Edit this post</a>
</div>
<h3>Comments</h3>
-
-<ol>{{# comments }}
- <li>{{{ comment }}}</li>
-{{/ comments }}</ol>
-
-<% form_for [@post, @comment] do |f| %>
- <div><%= f.label :body, "New comment" %>
- <%= f.text_area :body, :rows => 5, :columns => 40 %></div>
- <div><%= f.submit "Say your mind" %></div>
-<% end %>
+{{# comments? }}
+<ol>
+ {{# comments }}
+ <li>{{ comment }}</li>
+ {{/ comments }}
+</ol>
+{{/ comments? }}
View
13 app/views/posts/index.rb
@@ -1,8 +1,17 @@
class Posts::Index < Mustache::Rails
+ def posts?
+ not @posts.empty?
+ end
+
def posts
@posts.map do |post|
- { :title => link_to(post.title, post),
- :body => simple_format(post.body) }
+ { :title => post.title,
+ :body => simple_format(post.body),
+ :url => url_for(post) }
end
end
+
+ def new_post_link
+ link_to "New post", new_post_path
+ end
end
View
14 app/views/posts/post.rb
@@ -1,14 +0,0 @@
-class Posts::Post < Mustache::Rails
- def initialize(post)
- @post = post
- end
-
- def title
- debugger
- link_to @post.title, @post
- end
-
- def body
- simple_format @post.body
- end
-end
View
22 app/views/posts/show.rb
@@ -1,19 +1,31 @@
class Posts::Show < Mustache::Rails
def title
- link_to @post.title, @post
+ @post.title
+ end
+
+ def url
+ url_for @post
end
def body
simple_format @post.body
end
- def edit_link
- link_to "Edit", [:edit, @post]
+ def edit_path
+ url_for [:edit, @post]
+ end
+
+ def comments?
+ not _valid_comments.empty?
end
def comments
- @post.comments.select(&:valid?).map do |comment|
- { :comment => simple_format(comment.body) }
+ _valid_comments.map do |comment|
+ { :comment => comment.body }
end
end
+
+ def _valid_comments
+ @post.comments.reject(&:new_record?)
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.