Jquery code is not executed


Here is the

views/articles/show.html.erb file

<%= render @article %>
<div id="comments">
  <%= render @article.comments %>
<%= link_to "new comment", new_article_comment_path(@article, :format =>
:js), :remote => true, :id => 'new_comment_link' %>

and views/comments/new.js.erb

$("<%= escape_javascript render(file: 'comments/new.html.erb')

When I am clicking on the *new comment link* from the url -
http://localhost:3000/articles/2/ ... I am getting the Jquery code back
as show in the url - http://i.imgur.com/uRdWlsr.png

You can check the same in Github also -

Could you tell me why the Jquery is not being executed ?

Hows the controller rendering the response?

you might be missing a block like this on your controller action:

respond_to do |format|

format.js do



Here is the controller :-

class CommentsController < ApplicationController
  before_filter :load_article, :except => :destroy
  before_filter :authenticate, :only => :destroy
  def new
    respond_to do |format|

  def create
    @comment = @article.comments.new(comment_params)
    if @comment.save
      redirect_to @article, notice: 'Thanks for your comment'
      redirect_to @article, alert: 'Unable to add comment'

  def destroy
    @article = current_user.articles.find(params[:article_id])
    @comment = @article.comments.find(params[:id])
    redirect_to @article, notice: 'Comment Deleted'


  def load_article
    @article = Article.find(params[:article_id])

  def comment_params
    params.require(:comment).permit(:name, :email, :body)

Hey Arup,

what version of rails are you using?

Also have you read this:

try to google your error might help you.

all the best,