使用“responds_to_parent”时出现问题使用 iframe 和 AJAX 上传文件

发布于 2024-10-12 18:54:06 字数 1624 浏览 3 评论 0原文

我按照“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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情深如许 2024-10-19 18:54:06

已解决

我忘记添加 :url =>用户帐户路径+。 “js”。所以视图变成:

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

SOLVED

I had forgotten to add :url => users_account_path +. "js". So the view become:

<%= form_for(@user, :url => users_account_path +. "js", :html => { :multipart => true, :target => 'upload_frame' }) do |f| %>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文