0
votes

Rails 5 polymorphic Comment model, I am using devise.

When I create "new" comment, the params permitted => always false; Even I use params.permit(:all)

class Comment < ApplicationRecord
    belongs_to :commentable, polymorphic: true
    has_many :comments, as: :commentable   
    default_scope ->{ order('created_at DESC') }   
    validates_presence_of :title
    validates_presence_of :description   
end

views/comments/_form.html.erb

<%= form_with(model: comment, local: true) do |form| %> 

comments_controller.rb

    def comment_params  
        params.fetch(:client, {})    
        params.require(:comment).permit(:title, :description)
        params.permit(:all)
        byebug
    end

82:       params.fetch(:client, {})    
83:       params.require(:comment).permit(:title, :description)
84:       #params.permit(:title, :description, :client_id)
85:       params.permit(:all)
86:       byebug
=>  87:     end
88: 
89:    def find_commentable
90:      # @commentable = Client.find(params[:client_id]) 
if params[:client_id]    
91:      # for now


(byebug) params
1
Can you please add your comments#create action to your question? - slehmann36

1 Answers

0
votes

I solved my problem, by adding :commentable_id, and commentable_type to comment_params(), because Comment is polymorphic model.

def comment_params
params.fetch(:client, {})
params.require(:comment).permit( :title, :description, :commentable_id, :commentable_type) end

Thank you for helping