Ajax question

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”}) %>

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

<% @skills.each do |skill| %>

<% end %>
Title Parent
<%= skill.title %> <%= skill.parent_id %>

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.

On Nov 29, 7:11pm, DmitryS [email protected] wrote:

<% @skills.each do |skill| %>

The files in assets there aren’t passed through erb, they’re not
supposed to reference application contents etc. They’re completely
static js, css etc files that rails does clever stuff to ensure that
they are delivered to clients in a way that is efficient, cache
friendly etc.
If you want a js template to be rendered for your action then it
should live in the same place as your other templates (i.e. app/view/
skills)

Fred

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs