ruby - Rails polymorphic comments ajax - 500 (Internal Server Error) -
i used tutorial making polymorphic comments
https://gorails.com/episodes/comments-with-polymorphic-associations
it works fine when set remote true comments form got 505 error(the new comment not appended list) when trying add new comment.
but when reload page new comment appears in list.
what can wrong here?
i got files in views/comments folder:

create.js
<% unless @comment.errors.any? %> $("ul.comments").append('<%= j render "comments/comment" %>') $("#new_comment")[0].reset(); <% end %> _form.html.erb
<%= simple_form_for([commentable, comment.new], remote: true) |f| %> <%= f.input :body, label: false %> <%= f.button :submit, "submit" %> <% end %> comments_controller.rb
def create @comment = @commentable.comments.new(comment_params) @comment.user = current_user @comment.save respond_to |format| format.html { redirect_to @commentable, notice: "your comment added."} format.js end end _comment.html.erb
<li class="comment"> <b><%= comment.user.try(:username) %>:</b> <%= comment.body%> </li> console

up
i got routes post
resources :posts resources :comments, module: :posts end + controllers/posts/comments_controller
class posts::commentscontroller < commentscontroller before_action :set_commentable private def set_commentable @commentable = post.friendly.find(params[:post_id]) end end the folder structure looks same here https://github.com/excid3/gorails-episode-36/tree/master/app/controllers
the response tab shows this
undefined local variable or method `comment' #<#<class:0x007f993d3c5450>:0x007f99450a6190> trace of template inclusion: app/views/comments/create.js.erb and when replace
<%= j render @comment %> text appends list on submit
ok problem _comment.html erb
updated create.js instance variable comment , works now.
<% unless @comment.errors.any? %> $("ul.comments").append('<%= j render partial: "comments/comment", locals:{comment: @comment} %>') $("#new_comment")[0].reset(); <% end %>
Comments
Post a Comment