views:

122

answers:

3
  • 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...?
A: 

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.

Pär Wieslander
actually, it works in the separate RJS file (which means that prototype.js is included) but it is not working in controller... :( something else is going on here...
Jamal Abdul Nasir
A: 

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'

Salil
A: 

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.

dombesz