Hello, could you please explain what's wrong with this code:
Rails 3.1.1
skills_controller.rb
class SkillsController < ApplicationController # GET /skills # GET /skills.json def index @skills = Skill.all
respond_to do |format| format.html # index.html.erb #format.json { render json: @skills } format.js end end end
index.html.erb
<%= collection_select(nil, :id, @skills, :id, :title, {:prompt=>"Select one", :id=>:id},{:id=>"select_skill"}) %> <div id="skills_list"> </div>
app/assets/javascripts/index.js
$(document).ready(function() { $("#select_skill").change(function() { $("#skills_list").append("<%= escape_javascript(render :partial=>'skills_list') %>"); }); });
_skills_list.html.erb
<div id="skills_list"> <table> <tr> <th>Title</th> <th>Parent</th> </tr>
<% @skills.each do |skill| %> <tr> <td><%= skill.title %></td> <td><%= skill.parent_id %></td> </tr> <% end %> </table>
</div>
It finally prints <%= escape_javascript(render :partial=>'skills_list') %> instead of rendering skills list. I would appreciate if you tell me why.
Thank you in advance, Dmitry.