Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class RecipesController < ApplicationController
- before_action :authenticate_chef!, except: [:index, :show]
- def show
- @recipe = Recipe.find(params[:id])
- @comments = @recipe.comment_threads.order('created_at desc')
- @user_who_commented = current_chef
- @new_comment = Comment.build_from(@recipe, @user_who_commented.id, "")
- end
- ...
- class CommentsController < ApplicationController
- before_action :authenticate_chef!
- def create
- commentable = commentable_type.constantize.find(commentable_id)
- @user_who_commented = current_chef
- @comment = Comment.build_from(commentable, @user_who_commented.id, body)
- respond_to do |format|
- if @comment.save
- make_child_comment
- format.html { redirect_to(:back, :notice => 'Comment was successfully added.') }
- else
- format.html { render :action => "new" }
- end
- end
- end
- ...
- class Recipe < ActiveRecord::Base
- acts_as_commentable
- ...
- <%= render partial: "comments/template", locals: {commentable: @recipe, new_comment: @comment} %>
- <% if current_user_id? %>
- заданное значение current_chef
- <% else %>
- Войдите чтобы ответить
- <% end %>
Add Comment
Please, Sign In to add comment