Problem getting form_remote_tag to work with image upload

Hey guys,

I am trying to pass the parameters for the file being upload, but the
params[] are not being passed. Ive read through some posts and realize
this is an issue with RoR.

I read through some of the posts and someone suggested using:

http://svn.kylemaxwell.com/form_remote_upload/trunk/

I tried to install it, and although I thought I installed it correctly,
it doesn’t work.

I’m using Rails 1.1 .

Anyone been able to get this working. Solutions very welcome. :slight_smile:

Yeah, Im having the same problem too…

On Jul 21, 2006, at 11:53 PM, Eric G. wrote:

I tried to install it, and although I thought I installed it
Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails

I had to deal with this issue recently and the form_remote_upload
conflicted with other plugins I have installed and was hard to use to
reply with rjs and have it eval in the parent window. I found another
plugin that makes this much more straightforward.

http://sean.treadway.info/svn/plugins/responds_to_parent/README

-Ezra

Alien8 Recordings wrote:
Besides modifying these two files, how did you install it in the first
place, did you just put these under a folder in vendor/plugins. I know,
kinda a newby question…sorry guys…

Hi,

I got it to work. I had to modify the codes slightly… I actually
forget what I modified now, but here’s the code I have in the two files.

Take care,
Sean


frt_upload_helper.rb:

module ActionView
module Helpers
module PrototypeHelper
alias_method :form_remote_tag_old, :form_remote_tag
def form_remote_tag(options = {})
if options[:html] && options[:html][:multipart]
uid = “a#{Time.now.to_f.hash}”
<<-STR

<form method=“post” action="#{url_for options[:url].update
({:iframe_remote => true})}" enctype=“multipart/form-data” target="#
{uid}" #{%(onsubmit="#{options[:loading]}") if options[:loading]}>
STR
else
form_remote_tag_old(options)
end
end
end
end
end

Hi,

I got it to work. I had to modify the codes slightly… I actually
forget what I modified now, but here’s the code I have in the two files.

Take care,
Sean


frt_upload_helper.rb:

module ActionView
module Helpers
module PrototypeHelper
alias_method :form_remote_tag_old, :form_remote_tag
def form_remote_tag(options = {})
if options[:html] && options[:html][:multipart]
uid = “a#{Time.now.to_f.hash}”
<<-STR

<form method=“post” action="#{url_for options[:url].update
({:iframe_remote => true})}" enctype=“multipart/form-data” target="#
{uid}" #{%(onsubmit="#{options[:loading]}") if options[:loading]}>
STR
else
form_remote_tag_old(options)
end
end
end
end
end


frt_upload_filter.rb


Safari, and possibly other browsers, want to see content-type=text/

html to

trigger an iframe onload event. We will oblige, but it’s annoying.

module FrtUploadFilter
def frt_upload_filter
if params[:iframe_remote]
response.headers[“Content-Type”] = “text/html”
rb = response.body.dup
response.body = <<-STR


#{text_area_tag “content”, rb, :style => “width:
100%;height:100%”}


STR
end
end
end

class ActionController::Base
include FrtUploadFilter
include ActionView::Helpers::FormTagHelper
include ActionView::Helpers::FormHelper
include ActionView::Helpers::TagHelper
def self.inherited(newclass)
super newclass
if newclass == ApplicationController
newclass.class_eval do
after_filter :frt_upload_filter
end
end
end
end

On 22-Jul-06, at 2:53 AM, Eric G. wrote:

I tried to install it, and although I thought I installed it
Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails


ALIEN8 RECORDINGS
P.O. BOX 666, STATION R
MONTREAL, QC
CANADA, H2S 3L1

http://www.alien8recordings.com

Hey guys, I got the plugin installed and working, kinda.

Any of you guys know how to designate which element in your page will be
updated. I know that for the original form_remote_tag, you use
:update=>"".

Here that doesnt work.

It runs through the action in my controller but it doesnt execute the
render :partial command I have at the end of it. It does go through the
entire code though and gets the parameters from the incoming file.

How do you get this new plugin actually rendering a partial inside the
page?

Hi Eric,

I’m using the plugin with standard rjs rather than the :update
paramter on the form_remote_tag. So in my view for the form I have:

<%= form_remote_tag :url => { :action => :add_image, :id => @artist },
					:loading => "Element.show('add_image_spinner')",
					:html => {:multipart => true} %>

And in my controller I have:
def add_image
#blah blah whatever you want for your controller logic…

   # Display the newly updated image.... (this part could be put

in a separte .rjs file if you like…
render :update do |page|
page[:images].replace_html :partial => ‘images’, :object =>
@artist
page[“artistimage_#
{@new_artist_image.id}”].visual_effect :highlight, :startcolor =>
#cf2121”, :endcolor => “#cccccc
end

end

Hope that helps…

Sean

On 23-Jul-06, at 6:01 PM, Eric G. wrote:

render :partial command I have at the end of it. It does go through
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails


ALIEN8 RECORDINGS
P.O. BOX 666, STATION R
MONTREAL, QC
CANADA, H2S 3L1

http://www.alien8recordings.com

hey Ezra,

I tried out that plugin as well. The problem with it is that it sends
params[:uploaded_file] as a string not as a file object.

Hey Sean,

I put this at the bottom of my controller:

render :update do |page|
page[:images].replace_html :partial => ‘images’, :object
=>@artist

I of course adjusted it for my content. This didnt work either. Well in
a way it did work because it executed commands that came after it and
didnt give me any errors.

For example, I had a puts command after it which worked. I dont
understand why it does execute and redirect, render :updates or :partial
actions.

Sean, I’m not using your update because when I use it my app can’t use
the helper methods I defined in my app helper directory. I dont know
why.

Anybody got this thing working.

Hey Ezra,

I tried it out. I got it to recognize the file. However, even with the
line:

              responds_to_parent do
              render :update do |page|
              page.replace_html "toolbox_photos", :partial => 

‘toolbox_photos’
end
end

it renders it as text in the partial, is it supposed to do that?
toolbox_photos is the name of the DIV.

Hey Ezra,

I tried it out. I got it to recognize the file. However, even with the
line:

              responds_to_parent do
              render :update do |page|
              page.replace_html "toolbox_photos", :partial => 

‘toolbox_photos’
end
end

it renders it as text in the partial, is it supposed to do that?
toolbox_photos is the name of the DIV.

BTW,

I have this in my view:

  <form target="frame" action="upload_pic" 

ENCTYPE=“multipart/form-data” method=“post”>
<%= file_field_tag “file” %>
<%= submit_tag “Submit” %>

  <iframe id='frame' name="frame"></iframe>

On Jul 23, 2006, at 8:27 PM, Eric G. wrote:

Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails

Eric-

Well when rails accepts file uploads and they are smaller then a

certain size you will get a StringIO object. If they are bigger then
a certain size you get a File object. A StringIO will still respond
to read and many other methods that file does so you can almost treat
them the same way. Here’s a littel form and action to handle it

def upload
file = params[:uploaded_data].read
# now you can do what you want with the file object
# no matter if its a StringIO or a File.
responds_to_parent do
render :update do |page|
page.replace_html “file_upload_form”, :partial => ‘fileform’
page.visual_effect :highlight, “file_list”
page.hide ‘progress_indicator’
end
end
end

<%= start_form_tag({:controller => 'file_group', :action => 'upload'}, {:multipart => true, :target => "upload_iframe", :onsubmit => "Element.show('progress_indicator')}) %>
 <p>Choose File: <input id='data' name='uploaded_data'

type=‘file’ size=‘46’ />


<%= submit_tag :Upload %>


hope that helps

-Ezra

And whats really weird is this:

              responds_to_parent do
              render :update do |page|
              page.replace_html "toolbox_photos", :partial =>

‘toolbox_photos’
end
end

In that if I replace :partial => ‘toolbox_photos’ with something like
testing’, It will actually render it in that DIV, if I use the
render command it renders it as text in the iFrame, doing nothing to the
DIV whatsoever.

On Jul 24, 2006, at 2:22 AM, Eric G. wrote:

              end

ENCTYPE=“multipart/form-data” method=“post”>
<%= file_field_tag “file” %>
<%= submit_tag “Submit” %>

  <iframe id='frame' name="frame"></iframe>


Posted via http://www.ruby-forum.com/.


I am not sure what you mean here? What renders as text? Can you show
your toolbox_photos partial file? Can you explain what it is you are
trying to do again?

-Ezra

IS REPLACE BY:

So I wonder if responds_to_parent is changinf the scope inside the
block. Can you try to render_to_string and then replace_html with
that? Like this:

def upload
toolbox_partial = render_to_string :partial => ‘toolbox_photos’
responds_to_parent do
render :update do |page|
page.replace_html “toolbox_photos”, toolbox_partial
end
end
end

-Ezra

Here is my partial file:

<% @pictures.each do |picture| %>


<%= ‘’ %>
<%= draggable_element picture.id.to_s, {:revert => true,
:reverteffect => “function(element, top_offset, left_offset)
{dur=.0001;new Effect.MoveBy(element, -top_offset, -left_offset,
{duration:dur})}”} %>
        </div>

<% end %>

When I say that it renders as text. What I am saying is that the partial
renders itself in the iframe with some weird characters. It gets the
code in some weird way from the partial file. I know because I looked at
the source inside the frame.

However, if I replace the render :partial part from the controller with
any generic html code, it renders in the correct div.

So for example:

              responds_to_parent do
              render :update do |page|
              page.replace_html "toolbox_photos", :partial =>

‘toolbox_photos’
end
end

IS REPLACE BY:

              responds_to_parent do
              render :update do |page|
              page.replace_html "toolbox_photos", '<b>testing</b>'
              end
              end

This will render in the correct DIV, however the first example with the
render partial will render in the Iframe

I am not sure what you mean here? What renders as text? Can you show
your toolbox_photos partial file? Can you explain what it is you are
trying to do again?

-Ezra

Do any of you guys know why tags inside partials could be
screwing things up? They either aren’t getting rendered or are screwing
up the whole rendering no matter if I use page.replace_html or
Ajax.Updater.

Any ideas?

Hey Ezra,

That didnt fix it, but I narrowed the problem down.

Basically in my partial I have

<% @pictures.each do |picture| %>


<%= ‘’ %>
<%= draggable_element picture.id.to_s, {:revert => true,
:reverteffect => “function(element, top_offset, left_offset)
{dur=.0001;new Effect.MoveBy(element, -top_offset, -left_offset,
{duration:dur})}”} %>
        </div>

<% end %>

The draggable element part screws things up. It renders into the script
tags, but because of the brackets and paranthesis I’m guessing its
screws things up.

I took out the <%= draggable_element %> part and it worked. However I
cant put in the javascript. Is there anyway to fix this? I tried taking
the actual code (ie and putting it straight in
there but it gave me the same error.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs