2009-08-31 79 views
0

我想在使用Rails的Ajax中顯示Flash的錯誤消息,但它沒有顯示它,並且我嘗試了幾種方法來做到這一點,但我不能修正它。我怎樣才能在rails中顯示ajax的錯誤

這裏是我的形式來顯示我的錯誤:

#flash-error.flash-error{:style => "display: none"} 
#flash-notice.flash-info{:style => "display: none"} 
    %h3 New Document 
    - form_for(:repo_document, :url => {:all_categories => @repo_categories, :action => "create", :format => "js", :query => params[:query]}, :html => { :id => "repo_document_form", :multipart => true, :target => 'upload_frame'}) do |form| 

這裏是控制器:

if !params[:stands] 
    respond_to do |format| 
     format.js do 
      responds_to_parent do 
      render :update do |page| 
       page.show "flash-error" 
       page.replace_html "flash-error","Please select stands you want to grant permission to view this stand." 
      end 
      end 
     end 
     return 
    end 
    end 

我在做什麼錯?

+0

在發佈之前,你應該多做一些診斷 - 確保你點擊了format.js塊,並嘗試在iframe中顯示flash,以確保它不是一個responds_to_parent錯誤。 – klochner 2009-08-31 16:42:06

回答

0

一個可能的解決方案是一個Ajax調用在行動

+0

我使用form_for發送ajax,而不是使用form_remote_tag ..因爲我正在上傳文件..並且它不支持form_remote_tag。 – 2009-08-31 12:50:22

2

js.rjs救援

def action 
    @true = params[:stands] 
    respond_to |format| 
    format.js 
    end 
end 
在action.js.rjs

#nothing here due to no errors - errors will appear if they happen 
<div id="error_block_dom_id"></div> 

if @true 
    # do true stuff 
else 
    page.replace_html 'error_block_dom_id', :text => 'This is my error' 
end 

和原始視圖文件,您從使Ajax調用

無法使用Flash的首要原因 - 只需更新帶有錯誤內容的DOM對象。

0

我想問題可能是在別處:元素的方法顯示(調用,它的當你叫page.show「閃錯誤」生成)不會刪除顯示:無 CSS樣式當它是在外部Css文件中給出。這是Prototype API文檔舊版本的引用。

因此,請嘗試添加顯示:無作爲您div的內嵌樣式。我希望這會有所幫助!