【问题标题】:Problem using 'responds_to_parent' with an iframe and AJAX to upload a file使用带有 iframe 和 AJAX 的“responds_to_parent”上传文件时出现问题
【发布时间】: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


    【解决方案1】:

    已解决

    我忘记添加:url =&gt; users_account_path +. "js"。所以视图变成:

    <%= form_for(@user, :url => users_account_path +. "js", :html => { :multipart => true, :target => 'upload_frame' }) do |f| %>
    

    【讨论】:

      猜你喜欢
      • 2014-06-02
      • 2020-10-11
      • 1970-01-01
      • 2010-10-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-04
      相关资源
      最近更新 更多