My application allows a user to make a list with different categories. While making a list, if the user decides they would like another category, they may create one without leaving the page. The new category will appear in the list, and the user can begin adding items to it.
我的应用程序允许用户创建具有不同类别的列表。在制作列表时,如果用户决定他们想要另一个类别,他们可以在不离开页面的情况下创建一个列表。新类别将显示在列表中,用户可以开始向其添加项目。
My issue seems to be that adding any Rails helpers (link_to, render) to my 'new.js.erb' file, it stops the script from doing it's thing. My new div and dropdown menu are not rendered. I get no errors on the console or the server logs. Just nothing. If I remove these methods, everything works fine.
我的问题似乎是将任何Rails助手(link_to,render)添加到我的'new.js.erb'文件中,它会阻止脚本执行此操作。我的新div和下拉菜单没有呈现。我在控制台或服务器日志上没有错误。根本不值一提。如果我删除这些方法,一切正常。
function addCategory(){
var lastCategory = '<%= current_user.categories[-2].name %>';
console.log(lastCategory);
$('#' + lastCategory).after("<h3 class='category'><%= @category.name %></h3>\
<div class='dropdown-button' data-toggle='collapse' data-target='#<%= @category.name %>'>\
<span class='glyphicon glyphicon-chevron-down'></span>\
</div>\
<div id='<%= @category.name %>' class='collapse'>\
<h4>Create a new item here:</h4>\
<div id='append<%= @category.id %>'></div>\
<%= link_to 'Home', root_url %>\ //does not work!
</div>");
}
It's just the link_to and other methods that seem to be causing a problem. All other erb tags <%= %> seem to work and render appropriately.
它只是link_to和其他似乎导致问题的方法。所有其他erb标记<%=%>似乎都可以正常工作和渲染。
My goal is to render a form and a link in this newly rendered dropdown section, but since the root of the problem seems to be Rails methods in general, I added a link_to home for clarity.
我的目标是在这个新呈现的下拉部分中呈现一个表单和一个链接,但由于问题的根源似乎是一般的Rails方法,为了清楚起见,我添加了一个link_to home。
1 个解决方案
#1
1
Damnit, I figured it out. Forget to add 'j' to my rails helpers to convert them to JavaScript
该死的,我明白了。忘记在我的rails帮助器中添加'j'以将它们转换为JavaScript
<%= j link_to "Home", root_url %>
#1
1
Damnit, I figured it out. Forget to add 'j' to my rails helpers to convert them to JavaScript
该死的,我明白了。忘记在我的rails帮助器中添加'j'以将它们转换为JavaScript
<%= j link_to "Home", root_url %>