(Rails,Javascript) RJS“找不到变量” 错误未提供详细信息
我遇到了涉及 javascript 的 Rails 问题。 基本上,我有以下代码:
<ul id="all-points">
<%for point in Point.find(:all)%>
<%domid = "point[all][#{point.id}]"%>
<li class="available-point" id='<%=domid%>'>
<span>
<%= link_to_remote "ADD",:url => {:action => "add_point"},
:html => {:style => "background: wheat; color: gray; text-decoration: none; border: 1px solid gray;"},
:with => "'point=' + #{domid}"
%>
</span>
(<%=point.source%>)   <%=point.name%>
</li>
<%= draggable_element(domid, :ghosting => true, :revert => true, :scroll => "window")%>
<%end%>
</ul>
但是,我不断收到 RJS 错误,告诉我“找不到变量:点”。 该错误与 DOMID 有关,因为当我将“point”一词更改为“alksdjflksdjfls”(又名垃圾)时,它会警告我有关垃圾名称的信息。 诚然,我对 Javascript 很生疏,但这个错误似乎没有提供足够的信息。 有人可以告诉我我的代码有什么问题吗?
时,错误出现在我的控制器中
def add_point
render :update do |page|
page.insert_html :bottom, "selected-points", "<li>test phrase</li>"
page.remove params[:point] #error occurs here
end
end
仅供参考,当我说:我也尝试过encodeURIComponent ,但似乎没有什么重要的。 另外,我同时使用 Safari 和 Firefox 进行调试。 想法?
最好的。
I'm having an issue with rails involving javascript. Basically, I have the following code:
<ul id="all-points">
<%for point in Point.find(:all)%>
<%domid = "point[all][#{point.id}]"%>
<li class="available-point" id='<%=domid%>'>
<span>
<%= link_to_remote "ADD",:url => {:action => "add_point"},
:html => {:style => "background: wheat; color: gray; text-decoration: none; border: 1px solid gray;"},
:with => "'point=' + #{domid}"
%>
</span>
(<%=point.source%>)   <%=point.name%>
</li>
<%= draggable_element(domid, :ghosting => true, :revert => true, :scroll => "window")%>
<%end%>
</ul>
However, I keep receiving RJS errors telling me "Can't find variable: point". The error has something to do with DOMID as when I change the word "point" to "alksdjflksdjfls" (a.k.a. garbage), it warns me about the garbage name. I'm admittedly rusty when it comes to Javascript, but this error doesn't seem to give enough info. Can someone please tell me what is wrong with my code?
FYI, the error comes in my controller when I say:
def add_point
render :update do |page|
page.insert_html :bottom, "selected-points", "<li>test phrase</li>"
page.remove params[:point] #error occurs here
end
end
I've tried encodeURIComponent as well, but nothing seems to matter. Also, I'm using both Safari and Firefox to debug. Thoughts?
Best.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
哇。 没关系。 是一个试图过于严格地遵循一个例子的例子。 字面主义失败了! 将我的“:with”调整为“point = #{domid}”后,一切正常。
Wow. Nevermind. Was a case of attempting to follow an example too closely. Literalism FAIL! After adjusting my ":with" to "point = #{domid}" everything worked.