Skip to content
Browse files

Create a new Comment

  • Loading branch information...
1 parent fbc7acf commit f2d8a895084c6cb4f5daa6bed00ebcd303fc5083 @xmonkey committed
Showing with 14 additions and 1 deletion.
  1. +7 −0 app/controllers/comments_controller.rb
  2. +4 −0 app/views/posts/show.html.erb
  3. +3 −1 config/routes.rb
View
7 app/controllers/comments_controller.rb
@@ -0,0 +1,7 @@
+class CommentsController < ApplicationController
+ def create
+ @post = Post.find(params[:post_id])
+ @post.comments.create params[:comment]
+ redirect_to @post
+ end
+end
View
4 app/views/posts/show.html.erb
@@ -5,3 +5,7 @@
<li> <%= comment.content %> </li>
<% end %>
</ul>
+<%= form_for @post.comments.new, :url => post_comments_path(@post) do |f| %>
+ <%= f.text_area :content, :size => "60x12" %>
+ <%= f.submit "Create" %>
+<% end %>
View
4 config/routes.rb
@@ -1,5 +1,7 @@
CourseProject::Application.routes.draw do
#root to: "main#index"
root to: "posts#index"
- resources :posts, :only => [:index, :show]
+ resources :posts, :only => [:index, :show] do
+ resources :comments, :only => :create
+ end
end

0 comments on commit f2d8a89

Please sign in to comment.
Something went wrong with that request. Please try again.