使用“responds_to_parent”时出现问题使用 iframe 和 AJAX 上传文件
我按照“AJAX 文件上传中的说明进行操作在Rails 中使用attachment_fu 和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
尝试提交表单,所有有关文件上传的工作(回形针处理正确的文件,...)并且在日志文件中没有错误。
唯一不起作用的是 AJAX 部分。在示例中,
page.replace_html :test, "This is the resulting test"
page << "alert($('stuff').innerHTML)"
不要更新页面(顺便说一句:这些应该在哪里起作用?在“主视图”中还是在“iframe 视图”中?)。如果我尝试删除“respons_to_parent”语句或者将它们放入“action.js.rjs”文件中,它也不起作用。
我哪里错了?
I followed instructions from the "AJAX file uploads in Rails using attachment_fu and responds_to_parent" article. In my case I am using Ruby on Rails 3 and Paperclip.
What I made is the following:
I have installed the 'respons_to_parent' plugin running this command in the Terminal:
rails plugin install git://github.com/itkin/respond_to_parent.git
After installing, I restart Apache.
In my view I have:
<%= 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>
In my controller I have
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
Trying to submit the form, all about the file uploading works (Paperclip handle correclty files, ...) and in the log file there aren't errors.
The only thing that isn't working is the AJAX part. In the example
page.replace_html :test, "This is the resulting test"
page << "alert($('stuff').innerHTML)"
don't update the page (BTW: where these should have effect? in the "main view" or in the "iframe view"?). It doesn't work also if I try to delete the 'respons_to_parent' statement or if I put them in the 'action.js.rjs' file.
Where I am wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
已解决
我忘记添加
:url =>用户帐户路径+。 “js”
。所以视图变成:SOLVED
I had forgotten to add
:url => users_account_path +. "js"
. So the view become: