RJS in controller
- i have put the following rjs in a controller... but it gives me the following error...
TypeError: Element.update is not a function
respond_to do |format|
format.js do
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
end
- so how can i get rid of this error...?
Probably it's wrong because you try to use responds_to_parent within a respond_to block.
I don't know if you can mix them. I suggest to try without the respond_to block. To respond properly to request types you can do like
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
In this way only responds with js, when was an ajax call. But i suggest to use rjs file instead rendering from controller.
in your controller only write
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
and whaterver you are using for Ajax link_to_remote
or anything else don't write
:update=>'some_div'
It sounds like you've forgotten to include prototype.js
in your layout. Make sure you have
<%= javascript_include_tag "prototype" %>
in the HEAD section of your document layout.
精彩评论