2009-08-31 78 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的内嵌样式。我希望这会有所帮助!