Permalink
Browse files

07| Rendering Stored Information

Adding the messages `index` route
Creating the messages `index` action
Creating the messages `index` viwe
Adding redirection to the messages index from the messages `create` action
  • Loading branch information...
robertodecurnex committed Aug 30, 2011
1 parent 33fcb3c commit 9492639f464123c4f9dae170fce675a8b465a4ff
@@ -2,8 +2,25 @@ class MessagesController
include Pakyow::Helpers
+ def index
+ # Gets the full collection of stored messages
+ messages = Message.all
+
+ # * Takes the html elemetn with id = "message"
+ view = presenter.view.find('#message')
+
+ # * Creates a copy for each message
+ # * Fills the *author* and *body* spans with
+ # each message namesake attribute value
+ view.repeat_for(messages)
+ end
+
def create
Message.new(request.params['message']).save
+
+ # Redirect to the messages index after
+ # the message creation
+ app.redirect_to('/messages')
end
end
@@ -13,6 +13,12 @@ class Message
# used
@@latest_id = 0
+
+ # Returns the stored collection of messages
+
+ def self.all
+ @@messages
+ end
# Initialize the Message attributes given a
# hash of :attribute_name => :attribute_value
@@ -33,4 +39,3 @@ def save
end
end
-
View
@@ -0,0 +1,6 @@
+<p>
+ <strong><span itemprop="message[author]"></span></strong> says:
+ <br />
+ <span itemprop="message[body]"></span>
+</p>
+
@@ -0,0 +1,5 @@
+<h1>Recent Messages</h1>
+
+<a href="/messages/new">Post a Message</a>
+
+<div id="message"></div>
View
@@ -11,6 +11,8 @@ class Application < Pakyow::Application
routes do
default :ApplicationController, :index
+ get 'messages', :MessagesController, :index
+
post 'messages', :MessagesController, :create
end

0 comments on commit 9492639

Please sign in to comment.