【问题标题】:(Rails,Javascript) RJS "Can't find variable" error not providing detailed information(Rails,Javascript)RJS“找不到变量”错误未提供详细信息
【发布时间】:2009-07-05 03:42:45
【问题描述】:

我遇到了涉及 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%>) &nbsp <%=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 进行调试。想法?

最好的。

【问题讨论】:

    标签: javascript ruby-on-rails variables rjs


    【解决方案1】:

    哇。没关系。是一个试图过于密切地遵循一个例子的例子。文学失败!将我的 ":with" 调整为 "point = #{domid}" 后一切正常。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-12-07
      • 1970-01-01
      • 1970-01-01
      • 2016-07-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多