I have a lot of js files like new.js, index.js, create.js etc that handles my Ajax calls and other jquery code As the have many common code snippets I have tried to use partial js files For example I have a new.js file that calls a partial _new.js
new.js <%= render :partial=>‘new’, :formats=>[:js],:handlers=>[:erb] %>
_new.js
<% if params[:group_id]%>
$(“#group_participants_content”).html(“<%= escape_javascript(render(:partial=>‘form’))%>”);
$(“.remote_selected”).removeClass(“selected remote_selected simple-navigation-active-leaf”);
$(“#group_mail”).addClass(" remote_selected simple-navigation-active-leaf");
<%else%>
$(“#users_content”).html(“<%= escape_javascript(render(:partial=>‘form’))%>”);
$(“.remote_selected”).removeClass(“selected remote_selected simple-navigation-active-leaf”)
$(“#mail”).addClass(“remote_selected simple-navigation-active-leaf”);
<%end%>
// Change our States
History.replaceState({action:‘<%= “#{controller.action_name}/#{controller_name}” %>’}, ‘<%= “#{controller.action_name.titleize} #{controller_name}” %>’, ‘?action=<%= “#{controller.action_name}/#{controller_name}” %>’);
var url=History.getState().url;
$(“#help”).attr(‘href’,“/helps/0?url=”+url)
That works but to be useful I would like to add locals as <%= render :partial=>‘new’, :formats=>[:js],:handlers=>[:erb], locals=>{id=>“#group_participants_content”}%> and change _new.js to $(‘"’+id+‘"’).html(“<%= escape_javascript(render(:partial=>‘form’))%>”); However that does not work- The js file seems then not to be loaded at all
Anyone that has any suggestion of what is wrong ?
Appreciate any help ?