【发布时间】:2011-01-20 06:53:19
【问题描述】:
我按照“AJAX file uploads in Rails using attachment_fu and responds_to_parent”文章中的说明进行操作。就我而言,我使用的是 Ruby on Rails 3 和 Paperclip。
我做了如下:
我已在终端中安装了运行此命令的“respons_to_parent”插件:
rails plugin install git://github.com/itkin/respond_to_parent.git
安装后,我重新启动 Apache。
在我看来,我有:
<%= form_for(@user, :html => { :multipart => true, :target => 'upload_frame' }) do |f| %>
<%= f.file_field :avatar %>
<%= f.submit "Submit" %>
<% end %>
<div id="test">Here is a test</div>
<div id="stuff">Here is some stuff</div>
<iframe id='upload_frame' name="upload_frame" style="width:1px;height:1px;border:0px" ></iframe>
在我的控制器中
def action
respond_to do |format|
...
format.js {
responds_to_parent do
render :update do |page|
page.replace_html :test, "This is the resulting test"
page << "alert($('stuff').innerHTML)"
end
end
end
end
end
尝试提交表单,所有关于文件上传工作(Paperclip 处理正确文件,...)并且在日志文件中没有错误。
唯一不起作用的是 AJAX 部分。在示例中
page.replace_html :test, "This is the resulting test"
page << "alert($('stuff').innerHTML)"
不要更新页面(顺便说一句:这些应该在哪里起作用?在“主视图”或“iframe 视图”中?)。如果我尝试删除“respons_to_parent”语句或将它们放入“action.js.rjs”文件中,它也不起作用。
我哪里错了?
【问题讨论】:
标签: ruby-on-rails ruby ajax ruby-on-rails-3 response