How to Submit Polymorphic Comments on Feed? [Error]

前端 未结 2 1791
你的背包
你的背包 2020-12-21 12:51

If a user clicks the [+ Comment] button

\"enter

he is confron

相关标签:
2条回答
  • 2020-12-21 13:23

    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)
    
    0 讨论(0)
  • 2020-12-21 13:27

    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).

    0 讨论(0)
提交回复
热议问题