Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Comment < ActiveRecord::Base
- belongs_to :post
- end
- <%= form_for([@post, @post.comments.build]) do |post_comment_form| %>
- <div class="field">
- <%= post_comment_form.label :commenter %><br />
- <%= post_comment_form.text_field :commenter %>
- </div>
- <div class="field">
- <%= post_comment_form.label :body %><br />
- <%= post_comment_form.text_area :body %>
- </div>
- <div class="actions">
- <%= post_comment_form.submit %>
- </div>
- <% end %>
- def edit
- @post = Post.find(params[:post_id])
- @comment = @post.comments.find(params[:id])
- end
- def create
- @post = Post.find(params[:post_id])
- @comment = @post.comments.create(params[:comment])
- redirect_to post_path(@post)
- end
- def update
- #@post = Post.find(params[:post_id])
- #@comment = @post.comments.find(params[:id])
- respond_to do |format|
- #if @post.comments.update_attributes(params[:comment])
- if @comment.update_attributes(params[:comment])
- format.html { redirect_to @comment, notice: 'Comment was successfully updated.' }
- format.json { head :no_content }
- else
- format.html { render action: "edit" }
- format.json { render json: @comment.errors, status: :unprocessable_entity }
- end
- end
- end
- def new
- @post = Post.new
- @comment = @post.comments.build
- end
- def edit
- @post = Post.find(params[:post_id])
- @comment = @post.comments.find(params[:id])
- end
- <%= form_for([@post, @comment]) do |post_comment_form| %>
Add Comment
Please, Sign In to add comment