If a user clicks the [+ Comment] button
he is confron
The problem is, for this to work, it looks like it is setup for comments to be a nested resource of whatever you're commenting on in your routes file.
So, if you want comments on activities, you'd have:
resources :activites do
resources :comments
end
This way, when the #load_commentable method picks apart the request path, it'll get the commentable and id from the first two segments.
It looks, instead, like you're trying to use comments as a top level resource.
UPDATE: When you call your partial, simply pass along the url helper that the form should use. Like this:
<%= render "comments/form", new_comment: Comment.new(commentable_id: activity.id, commentable_type: activity.class.model_name), create_url: :activity_comments_path %>
Then, over in the partial, simply invoke that helper and pass the result as the url option - like this:
<%= form_for new_comment, url: send(create_url, new_comment.commentable)
In the load_commentable
before action, you could redirect to an error page or something if @commentable
is nil
. As it is, you are trying to access attributes of this nil
object in other methods (create
in the case of this error).