Sha256: d71173f12f3b386f4f35e434fd4a0d1bf8e2c926f6275122dd177d2cfa533f03
Contents?: true
Size: 942 Bytes
Versions: 31
Compression:
Stored size: 942 Bytes
Contents
class CommentsController < ApplicationController before_action :comment_params, only: [:create] before_action :load_commmentable def index @comments = @commentable.comments end def create @comment = @commentable.comments.new comment_params @comment.save! redirect_to [@commentable], notice: "Comment created" end private # def article_params # params.require(:comment).permit(:article_id) # end def comment_params resource = request.path.split('/')[1] commentable_id = "#{resource.singularize.to_sym}_id" #:article_id params.require(:comment).permit(:body, :user_id, commentable_id.to_sym) end def load_commmentable resource, id = request.path.split('/')[1,2] @commentable = resource.singularize.classify.constantize.find(id) end end
Version data entries
31 entries across 28 versions & 2 rubygems