Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

adds posts controller and routes and views

  • Loading branch information...
commit 8fafe8eea74867b7a756185c2fc16cecb76f0de2 1 parent dc2a2a2
@nesquena nesquena authored
View
12 app/controllers/posts.rb
@@ -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
View
7 app/helpers/posts_helper.rb
@@ -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
2  app/models/post.rb
@@ -1,3 +1,3 @@
class Post < ActiveRecord::Base
-
+
end
View
6 app/views/posts/_post.haml
@@ -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)
View
3  app/views/posts/index.haml
@@ -0,0 +1,3 @@
+%h1 Listing posts
+
+.posts= partial 'posts/post', :collection => @posts
View
8 app/views/posts/show.haml
@@ -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)
View
13 test/controllers/posts_controller_test.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.