2010-06-14 48 views
0
  • 我已經把下面的RJS在控制器...但它給了我下面的錯誤...

TypeError: Element.update is not a functionRJS在控制器

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 
  • 那麼,如何擺脫這個錯誤...?
+0

什麼是'responds_to_parent'? – 2010-06-14 13:09:43

+0

responds_to_parent實際上使控制器響應您的父文檔(PAGE) – 2010-06-14 13:28:18

回答

1

也許這是錯誤的,因爲你嘗試到respond_to代碼塊中使用responds_to_parent。

我不知道你是否可以混合它們。我建議嘗試沒有respond_to塊。 要正確地響應請求類型,你可以像

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 

這樣只能用JS迴應,是一個Ajax調用時。 但我建議使用rjs文件,而不是從控制器渲染。

0

這聽起來像你忘了在你的佈局中包含prototype.js。確保你有

<%= javascript_include_tag "prototype" %> 

在您的文檔佈局的HEAD部分。

+0

,它在單獨的RJS文件(這意味着包含prototype.js)中工作,但它不在控制器中工作... :( 其他是去這裏... – 2010-06-14 13:13:54

1
在控制器

只寫

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_to_remote或其他任何don't write:update=>'some_div'