Guest User

Untitled

a guest
Jun 28th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. class RecipesController < ApplicationController
  2. before_action :authenticate_chef!, except: [:index, :show]
  3. def show
  4. @recipe = Recipe.find(params[:id])
  5. @comments = @recipe.comment_threads.order('created_at desc')
  6. @user_who_commented = current_chef
  7. @new_comment = Comment.build_from(@recipe, @user_who_commented.id, "")
  8. end
  9. ...
  10.  
  11. class CommentsController < ApplicationController
  12. before_action :authenticate_chef!
  13.  
  14. def create
  15. commentable = commentable_type.constantize.find(commentable_id)
  16. @user_who_commented = current_chef
  17. @comment = Comment.build_from(commentable, @user_who_commented.id, body)
  18.  
  19. respond_to do |format|
  20. if @comment.save
  21. make_child_comment
  22. format.html { redirect_to(:back, :notice => 'Comment was successfully added.') }
  23. else
  24. format.html { render :action => "new" }
  25. end
  26. end
  27. end
  28. ...
  29.  
  30. class Recipe < ActiveRecord::Base
  31. acts_as_commentable
  32. ...
  33.  
  34. <%= render partial: "comments/template", locals: {commentable: @recipe, new_comment: @comment} %>
  35.  
  36. <% if current_user_id? %>
  37. заданное значение current_chef
  38. <% else %>
  39. Войдите чтобы ответить
  40. <% end %>
Add Comment
Please, Sign In to add comment