Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- resources :posts do
- resources :comments
- end
- <p><%= @post.title %></p>
- <h2>Comments:</h2>
- <div id='com'>
- <%= render @post.comments %>
- </div>
- <h2>Add a comment:</h2>
- <%= render "comments/form" %>
- <p>
- <strong>Commenter:</strong>
- <%= comment.commenter %>
- </p>
- <p>
- <strong>Comment:</strong>
- <%= comment.body %>
- </p>
- <%= link_to "Del", [comment.post, comment], :confirm => 'Are you sure?', :method => :delete %>
- <hr>
- <%= form_for([@post, @post.comments.build], remote: true) do |f| %>
- .
- .
- .
- class CommentsController < ApplicationController
- def create
- @post = Post.find(params[:post_id])
- @comment = @post.comments.create(params[:comment])
- respond_to do |format|
- format.html { redirect_to post_path(@post) }
- format.js
- end
- end
- $('#com').html("<%=j render @post.comments %>");
- <%= javascript_include_tag 'application' %>
- //= require jquery
- //= require jquery_ujs
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement