Topic: link_to :remote => true not executing rendered javascript

In my index page for users I have remote links for promoting/demoting users. I also have a <dd> element that displays each users current role. I want to update the users div showing the new role using jquery and highlight the changes.

Here is the <dd> element
<dd id="role_<%= user.id %>">Role: <%= user.role %></dd>

Here is the remote link
<%= link_to "Promote to Editor", make_editor_user_path(user, :format => :js), :remote => true %>

In my controller I have the following in respond_to

respond_to do |format|
  format.html { redirect_to(users_url) }
  format.js { @user }
  format.xml  { head :ok }
end

Here is the make_editor.js.erb code

$(<%= "user_#{@user.id}" %>).html("<%= escape_javascript(render(@user)) %>");
$(<%= "role_#{@user.id}" %>).css({'background-color':'#88ff88'}).animate({'background-color':'#ffffff'}, 2000);

When I click on the link instead of executing the javascript rendered from make_editor.js.erb it displays the javascript code to me directly in the browser. If I remove :format => :js from the link_to then it re-renders the whole page. It used to work when I was using rails 3.0.0 but not in Rails 3.0.3

Last edited by ecoulthard (2011-01-09 00:18:06)

Re: link_to :remote => true not executing rendered javascript

I fixed it. Turns out that I wasn't loading jquery.rails.js