Browse files

view individual posts

  • Loading branch information...
1 parent f13c643 commit 1a129ebfe375f6ba238aa89f3c45cb6e4c24f2d5 @steveklabnik steveklabnik committed Mar 5, 2012
View
8 app/controllers/blog_controller.rb
@@ -1,11 +1,15 @@
class BlogController < ApplicationController
- def show
+ def index
@posts = BlogPost.all.reverse
end
def create
@post = BlogPost.create(params[:blog_post])
- redirect_to admin_blog_path, :notice => "Blog Post created!"
+ redirect_to admin_blog_index_path, :notice => "Blog Post created!"
+ end
+
+ def show
+ @post = BlogPost.find(params[:id])
end
def admin
View
2 app/views/blog/admin.html.haml
@@ -1,7 +1,7 @@
%h1 Blog Admin
%h2 New Post
-= form_for @post, :url => blog_path do |f|
+= form_for @post, :url => blog_index_path do |f|
= f.label :title
= f.text_field :title
= f.label :content
View
9 app/views/blog/index.html.haml
@@ -0,0 +1,9 @@
+%h1 The Hackety Blog!
+
+- @posts.each do |post|
+ %h2= post.title
+ %h3= post.created_at
+ :markdown
+ #{post.content}
+ %hr/
+
View
13 app/views/blog/show.html.haml
@@ -1,9 +1,4 @@
-%h1 The Hackety Blog!
-
-- @posts.each do |post|
- %h2= post.title
- %h3= post.created_at
- :markdown
- #{post.content}
- %hr/
-
+%h1= @post.title
+%h3= @post.created_at
+:markdown
+ #{@post.content}
View
2 app/views/shared/menu/_footer.html.haml
@@ -1,6 +1,6 @@
= semantic_menu :class => "pills" do |root|
- root.add "Home", root_path
- - root.add "Blog", blog_path
+ - root.add "Blog", blog_index_path
- root.add "Questions", questions_path
- root.add "Programs", programs_path
- root.add "FAQ", faq_path
View
2 app/views/shared/menu/_main.html.haml
@@ -1,5 +1,5 @@
= semantic_menu :class => "nav" do |root|
- - root.add "Blog", blog_path
+ - root.add "Blog", blog_index_path
- root.add "Questions", questions_path
- root.add "Lessons", lessons_path
- root.add "Programs", programs_path
View
4 config/routes.rb
@@ -6,8 +6,8 @@
resources :answers
end
- resource :blog, :controller => "blog" do
- match "/admin", :to => "blog#admin"
+ resources :blog, :controller => "blog" do
+ match "admin", :on => :collection, :controller => "blog", :action => "admin"
end
get "/downloads/latest/:platform", :to => "static#download", :as => 'downloads'
View
6 features/blog.feature
@@ -8,6 +8,12 @@ Feature: Hackety Blog
Then I should see the title of that post
And I should see the content of that post
+ Scenario: Read a post
+ Given a blog post exists
+ When I visit a blog post
+ Then I should see the title of that post
+ And I should see the content of that post
+
Scenario: Post to the blog
Given I'm logged in as someone who can post to the blog
When I visit the blog admin page
View
5 features/step_definitions/blog_steps.rb
@@ -40,3 +40,8 @@
Then /^I should see that my post has been created$/ do
page.should have_content("Post created!")
end
+
+When /^I visit a blog post$/ do
+ visit blog_path(@post)
+end
+

0 comments on commit 1a129eb

Please sign in to comment.