2011-11-23 51 views
0

我在Internet Explorer中遇到了一个陌生人错误。form_for远程无法在Internet Explorer中工作

我有一个form_for with remote => true。

反过来,当调用创建操作时,会有一个关联的create.js.erb文件。

当我点击提交时,IE浏览器让我下载返回的create.js.erb文件。

这只发生在我试图上传图片的形式。

我不明白是什么问题。

该表单适用于Firefox和Chrome。

我正在使用remotipart进行图片上传(不确定是否有帮助)。

另外,我使用回形针作为图像附件。

下面我会发布我的视图,控制器和create.js.erb。

查看:

<% form_for @post, :remote => true, :html => {:multipart => true} do |f| %> 
         <%= f.text_area :message, :value => "What's up?" %> 
         <div id="newPostBottom"> 
          <div id="newPostBottomRight"> 
           <div id="loading"> 
            Sharing <%= image_tag('spinner.gif') %> 
           </div> 
           <%= f.submit "Share", :class => 'button' %> 
          </div> 
          <div id="newPostBottomLeft"> 
           <%= f.label :channel, "Select Channel:" %><%= f.select :channel, channels, :prompt => "Choose..." %> 
           <div id="postImageUpload"> 
            <%= image_tag('icons/camera.png', :id => 'postUploadImageIcon', :alt => 'Upload Image', :title => 'Upload Image') %> 
           </div> 
           <%= f.file_field :post_image %> 
          </div> 
         </div> 
        <% end %> 

控制器:

def create 
account = Account.getAccountById(session[:user]) 
@post = account.posts.build(params[:post]) 

payload = { 
    "account_id" => account.id, 
    "name" => account.name, 
    "message" => params[:post][:message], 
    "channel" => params[:post][:channel] 
} 
if @post.save 
    Pusher['front-post-feed-channel'].trigger('front-post-feed-create', payload) 
else 
    render :nothing => true 
end 

rescue ActiveRecord::RecordNotFound 
reset_session 
end 

Create.js.erb:

$("#post_message").val("What's up?"); 
$("#post_message").css({height: '30px'}); 
$("#newPostBottom").hide(); 
$("#postsHomeFeed").prepend("<%= escape_javascript(render(:partial => '/posts/new_post', :locals => {:post => @post})) %>"); 
$("#loading").hide(); 
$("#post_submit").show(); 
$("#post_channel").val(''); 
$("#post_post_image").val(''); 
if($(".noContent").length > 0) { 
$(".noContent").remove(); 
} 

得到任何帮助。

感谢,

布赖恩

回答

1

尝试包装你create.js.erb文件的内容在一个remotipart_response块:

<%= remotipart_response do %> 
    $("#post_message").val("What's up?"); 
    $("#post_message").css({height: '30px'}); 
    $("#newPostBottom").hide(); 
    $("#postsHomeFeed").prepend("<%= escape_javascript(render(:partial => '/posts/new_post', :locals => {:post => @post})) %>"); 
    $("#loading").hide(); 
    $("#post_submit").show(); 
    $("#post_channel").val(''); 
    $("#post_post_image").val(''); 
    if($(".noContent").length > 0) { 
    $(".noContent").remove(); 
    } 
<% end %> 
+0

是否有IE文件大小的限制?我做了你所说的,我现在可以得到尺寸较小的图像,但较大的图像不能。 – Brian

+0

得到它的工作。不得不添加你的建议加上一些JavaScript代码 – Brian

+0

您使用的是哪个版本的Gem?我认为最近的1.0版本摆脱了对周围区块的需求,但旧版本仍然需要它。 –

相关问题