commentable = commentable_type.constantize.find(commentable_id)
NameError in CommentsController#new
wrong constant name post
commentable = commentable_type.constantize.find(commentable_id)
NameError in CommentsController#new
wrong constant name post
Hi. Could you try the code below?
commentable = commentable_type.camelize.constantize.find(commentable_id)
I solved the problem by using values for polymorphic types that start with capital letters This looks like a better solution Thanks If constantize doesn’t convert the first char to upper case then what does it do?
It only tries to find and return an available constant with the specified name. But the string needs to be already in camel case.