Reputation: 6071
I am running into a stranger error in Internet Explorer.
I have a form_for with remote => true.
In turn, when the create action is called there is an associated create.js.erb file.
When I hit submit it IE the browser askes me to download the returned create.js.erb file.
This only occurs when I tried to upload an image in the form.
I do not understand what the problem is.
The form works in Firefox and Chrome.
I am using remotipart for the image upload (not sure if that helps).
In addition, I am using paperclip for the image attachments.
Below I will post my view, controller, and create.js.erb.
View:
<% 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 %>
Controller:
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();
}
Appreciate any help.
Thanks,
Brian
Upvotes: 0
Views: 414
Reputation: 124439
Try wrapping the contents of your create.js.erb
file in a remotipart_response
block:
<%= 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 %>
Upvotes: 1