daily pastebin goal
41%
SHARE
TWEET

Untitled

a guest Jan 20th, 2019 82 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Comment < ActiveRecord::Base
  2.   belongs_to :post
  3. end
  4.    
  5. <%= form_for([@post, @post.comments.build]) do |post_comment_form| %>
  6.     <div class="field">
  7.       <%= post_comment_form.label :commenter %><br />
  8.       <%= post_comment_form.text_field :commenter %>
  9.     </div>
  10.     <div class="field">
  11.       <%= post_comment_form.label :body %><br />
  12.       <%= post_comment_form.text_area :body %>
  13.     </div>
  14.     <div class="actions">
  15.       <%= post_comment_form.submit %>
  16.     </div>
  17. <% end %>
  18.    
  19. def edit
  20.     @post = Post.find(params[:post_id])
  21.     @comment = @post.comments.find(params[:id])
  22.   end
  23.  
  24.   def create
  25.     @post = Post.find(params[:post_id])
  26.     @comment = @post.comments.create(params[:comment])
  27.     redirect_to post_path(@post)
  28.   end
  29.  
  30.   def update
  31.     #@post = Post.find(params[:post_id])
  32.     #@comment = @post.comments.find(params[:id])
  33.  
  34.     respond_to do |format|
  35.       #if @post.comments.update_attributes(params[:comment])
  36.           if @comment.update_attributes(params[:comment])
  37.         format.html { redirect_to @comment, notice: 'Comment was successfully updated.' }
  38.         format.json { head :no_content }
  39.       else
  40.         format.html { render action: "edit" }
  41.         format.json { render json: @comment.errors, status: :unprocessable_entity }
  42.       end
  43.     end
  44.   end
  45.    
  46. def new
  47.   @post = Post.new
  48.   @comment = @post.comments.build
  49. end
  50.    
  51. def edit
  52.   @post = Post.find(params[:post_id])
  53.   @comment = @post.comments.find(params[:id])
  54. end
  55.    
  56. <%= form_for([@post, @comment]) do |post_comment_form| %>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top