I am trying to get new comments to update with ajax instead of a page reload. I followed the railscast tutorial but am getting a 500 internal server error in my js console. I was reading other posts and a lot of people are saying its a partial error but I can't figure it out. The comment will save before page reload but will not display until the page is reloaded.. Here is the comment controller
def create
@post = Post.find(params[:post_id])
@comment = Comment.create(params[:comment].permit(:content))
@comment.user_id = current_user.id
@comment.post_id = @post.id
if @comment.save
respond_to do |format|
format.html {redirect_to post_path(@post.comments)}
format.js
end
else
render 'new'
end
end
The create.js.erb file in the comment directory.
$('.comment').append('<%= j render @post.comments %>');
The comment form
<%= simple_form_for([@post, @post.comments.build], :remote => true, :input_html => { :data => { :url => '/post/:id', :type => :js } }) do |f| %>
<%= f.input :content, label: "Reply"%>
<%= f.button :submit, "Submit" %>
<% end %>