Permalink
Browse files

adds posts controller and routes and views

  • Loading branch information...
1 parent dc2a2a2 commit 8fafe8eea74867b7a756185c2fc16cecb76f0de2 @nesquena nesquena committed Mar 17, 2010
View
@@ -0,0 +1,12 @@
+SampleBlog.controllers :posts do
+ get :index do
+ @posts = Post.all
+ render 'posts/index'
+ end
+
+
+ get :show, :with => :id do
+ @post = Post.find_by_id(params[:id])
+ render 'posts/show'
+ end
+end
@@ -0,0 +1,7 @@
+# Helper methods defined here can be accessed in any controller or view in the application
+
+SampleBlog.helpers do
+ # def simple_helper_method
+ # ...
+ # end
+end
View
@@ -1,3 +1,3 @@
class Post < ActiveRecord::Base
-
+
end
@@ -0,0 +1,6 @@
+.post
+ .heading
+ %h2= link_to(post.title, url_for(:posts, :show, :id => post.id))
+ %p Posted by Admin
+ .contenta
+ = simple_format(post.body)
@@ -0,0 +1,3 @@
+%h1 Listing posts
+
+.posts= partial 'posts/post', :collection => @posts
@@ -0,0 +1,8 @@
+.post
+ .heading
+ %h2= @post.title
+ %p Posted by Admin
+ .contenta
+ = simple_format(@post.body)
+
+%p= link_to 'Back to all posts', url_for(:posts, :index)
@@ -0,0 +1,13 @@
+require File.dirname(__FILE__) + '/../test_config.rb'
+
+class PostsControllerTest < Test::Unit::TestCase
+ context "PostsController" do
+ setup do
+ get '/'
+ end
+
+ should "return hello world text" do
+ assert_equal "Hello World", last_response.body
+ end
+ end
+end

0 comments on commit 8fafe8e

Please sign in to comment.