带下拉列表的Ajax调用

I have trying to follow this question but I am stuck. In my controller I have:

 def index
    if params[:sort] == 'stars'
      @projects = [Project.first]
    else
      @projects = Project.all
    end

    respond_to do |format|
      format.html
      format.js { render 'populate_projects', :formats => [:js] }
    end
  end

in routes:

get '/inspire/:sort' => 'projects#index'

in view:

   = collection_select :project, :id, Project.all, :id, :name, {}, {:onchange => '$.get("/inspire/stars")'}
   %div#normal
    = render 'projects_list'
   %div#stars{ style: 'display: none' }

my _projects_list.html.haml has:

  %div
    - @projects.each do |project|
      %div
        %p
         #more code...

and finally in populate_projects.js.haml:

:plain
  $("#stars").html("#{escape_javascript render(partial: 'projects/projects_list')}");
  $("#normal").hide();
  $("#stars").show();

Probably the program doesn't make sense as I am testing if ajax call is working. However, what should happen is when I change the state of dropdown an ajax call must be made which renders 'propulate.js.haml' and list of projects must change from all to just first, but is not. In my terminal I can see that call is being made but 'populate.js.haml' is never rendered. Can someone please help!

Make sure your Ajax call requests the JS format:

= collection_select :project, :id, Project.all, :id, :name, {}, {:onchange => '$.get("/inspire/stars.js")'}

If you want to make an ajax call you need to include:

"data-remote" => true

See here for more information