Ruby on rails 控制器中的RJS 我已将以下RJ放入控制器中。。。但它给了我以下的错误
TypeError:Element.update不是函数Ruby on rails 控制器中的RJS 我已将以下RJ放入控制器中。。。但它给了我以下的错误,ruby-on-rails,rjs,Ruby On Rails,Rjs,TypeError:Element.update不是函数 那么我怎样才能摆脱这个错误 听起来你好像忘了在布局中包含prototype.js。确保你有 <%= javascript_include_tag "prototype" %> 在文档布局的标题部分。在控制器中仅写入 render :update do |page| page.replace_html 'errorLay', :text => "Page with the same name al
- 那么我怎样才能摆脱这个错误
prototype.js
。确保你有
<%= javascript_include_tag "prototype" %>
在文档布局的标题部分。在控制器中仅写入
render :update do |page|
page.replace_html 'errorLay', :text => "Page with the same name already exists."
page.show 'errorLay'
page.delay(2) do
page.hide 'errorLay'
end
end
无论您使用什么方式来进行Ajax
link\u to\u remote
或任何其他操作,都不要编写:update=>'some\u div'
可能是错误的,因为您试图在respond\u to block中使用responses\u to\u parent
我不知道你能不能把它们混在一起。我建议尝试不使用Response_来阻止。
要正确响应请求类型,可以执行以下操作
if request.xhr?
responds_to_parent do
render :update do |page|
page.replace_html 'errorLay', :text => "Page with the same name already exists."
page.show 'errorLay'
page.delay(2) do
page.hide 'errorLay'
end
end
end
end
这样,当调用ajax时,只使用js进行响应。
但是我建议使用rjs文件,而不是从控制器渲染。什么是Responses\u to\u parent
?Responses\u to\u parent使控制器响应您的父文档(页面)实际上,它在单独的rjs文件中工作(这意味着包含prototype.js),但在控制器中不工作…:(这里还发生了其他事情。。。
if request.xhr?
responds_to_parent do
render :update do |page|
page.replace_html 'errorLay', :text => "Page with the same name already exists."
page.show 'errorLay'
page.delay(2) do
page.hide 'errorLay'
end
end
end
end