So I’ve been following various tutorials to implement an ajax-like file
upload using responds_to_parent and iframe targets, but can’t quite
close the deal. My file uploads successfully, but the rjs doesn’t work
(my ‘events’ partial, which refreshes fine with this controller code
when called with form_remote_tag, doesn’t refresh).
Can anyone who’s done this before see what’s missing?
Thanks,
Peter
View:
<% form_tag({:action=>‘upload’}, :multipart => true, :target => “frame”)
do %>
<%= file_field_tag “uploaded_file” %>
<%= submit_tag ‘Upload’ %>
<% end %>
Controller:
def upload
event = Event.new
event.date = Date.today
if event.save
File.open("#{RAILS_ROOT}/uploaded.rtf", “wb”) do |f|
f.write(params[‘uploaded_file’].read)
end
responds_to_parent do
render :update do |page|
page.replace_html “event_list”, :partial => “events”
end
end
end
end