开发者

RJS in controller

开发者 https://www.devze.com 2023-01-03 21:41 出处:网络
i have put the following rjs in a controller... but it gives me the following error... TypeError: Element.update is not a function
  • 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消