Eric Gross
2006-Jul-22 06:53 UTC
[Rails] 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. :) -- Posted via http://www.ruby-forum.com/.
Guest
2006-Jul-23 04:10 UTC
[Rails] Re: Problem getting form_remote_tag to work with image uploa
Yeah, Im having the same problem too... -- Posted via http://www.ruby-forum.com/.
Alien8 Recordings
2006-Jul-23 15:32 UTC
[Rails] Problem getting form_remote_tag to work with image upload
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
<iframe name="#{uid}" id="#{uid}"
src="about:blank"
style="position:absolute;left:-100px;width:0px;height:0px;border:
0px"></iframe>
<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
<html>
<body onload="window.parent.evalScripts
(document.getElementById(''content'').value)">
#{text_area_tag "content", rb, :style => "width:
100%;height:100%"}
</body>
</html>
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 Gross wrote:
> 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. :)
>
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
______________
ALIEN8 RECORDINGS
P.O. BOX 666, STATION R
MONTREAL, QC
CANADA, H2S 3L1
http://www.alien8recordings.com
Ezra Zygmuntowicz
2006-Jul-23 19:35 UTC
[Rails] Problem getting form_remote_tag to work with image upload
On Jul 21, 2006, at 11:53 PM, Eric Gross wrote:> 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. :) > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/railsI 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
Eric Gross
2006-Jul-23 20:21 UTC
[Rails] Re: Problem getting form_remote_tag to work with image uploa
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 > <iframe name="#{uid}" id="#{uid}" src="about:blank" > style="position:absolute;left:-100px;width:0px;height:0px;border: > 0px"></iframe> > <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-- Posted via http://www.ruby-forum.com/.
Eric Gross
2006-Jul-23 22:01 UTC
[Rails] Re: Problem getting form_remote_tag to work with image uploa
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? -- Posted via http://www.ruby-forum.com/.
Alien8 Recordings
2006-Jul-24 00:05 UTC
[Rails] Re: Problem getting form_remote_tag to work with image uploa
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 Gross wrote:
> 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?
>
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
______________
ALIEN8 RECORDINGS
P.O. BOX 666, STATION R
MONTREAL, QC
CANADA, H2S 3L1
http://www.alien8recordings.com
Eric Gross
2006-Jul-24 03:14 UTC
[Rails] Re: Re: Problem getting form_remote_tag to work with image u
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.
--
Posted via http://www.ruby-forum.com/.
Eric Gross
2006-Jul-24 03:27 UTC
[Rails] Re: Re: Problem getting form_remote_tag to work with image u
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. -- Posted via http://www.ruby-forum.com/.
Ezra Zygmuntowicz
2006-Jul-24 04:54 UTC
[Rails] Re: Re: Problem getting form_remote_tag to work with image u
On Jul 23, 2006, at 8:27 PM, Eric Gross wrote:> 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. > > > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/railsEric- 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 <div id = ''file_upload_form''> <%= 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'' /></p> <p><%= submit_tag :Upload %> <span id=''progress_indicator>'' style=''display: none;''><img src=''/images/indicator_D6D6D6.gif''></span> </p> </form> </div> <iframe id="upload_iframe" name="upload_iframe" src="about:blank" style="position:absolute;left:-100px;width:0px;height:0px;border: 0px"></iframe> hope that helps -Ezra
Eric Gross
2006-Jul-24 09:19 UTC
[Rails] Re: Re: Re: Problem getting form_remote_tag to work with ima
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.
--
Posted via http://www.ruby-forum.com/.
Eric Gross
2006-Jul-24 09:22 UTC
[Rails] Re: Re: Re: Problem getting form_remote_tag to work with ima
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" %>
</form>
<iframe id=''frame''
name="frame"></iframe>
--
Posted via http://www.ruby-forum.com/.
Eric Gross
2006-Jul-24 09:32 UTC
[Rails] Re: Re: Re: Problem getting form_remote_tag to work with ima
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
''<b>testing</b>'', 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.
--
Posted via http://www.ruby-forum.com/.
Ezra Zygmuntowicz
2006-Jul-24 17:23 UTC
[Rails] Re: Re: Re: Problem getting form_remote_tag to work with ima
On Jul 24, 2006, at 2:22 AM, Eric Gross wrote:> 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" %> > </form> > > <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
Eric Gross
2006-Jul-25 02:24 UTC
[Rails] Re: Re: Re: Re: Problem getting form_remote_tag to work with
Here is my partial file:
<% @pictures.each do |picture| %>
<div class="thumb_frame">
<%= ''<img class="photo thumb"
onmouseover="bringFront(this.id);"
onmouseout="sendBack(this.id);"
name="'' + picture.name + ''" id="'' +
picture.id.to_s + ''"
src="/images/pictures/thumbs/'' + picture.id.to_s +
''.jpg" />'' %>
<%= 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
--
Posted via http://www.ruby-forum.com/.
Ezra Zygmuntowicz
2006-Jul-25 03:29 UTC
[Rails] Re: Re: Re: Re: Problem getting form_remote_tag to work with
> > 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 >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
Eric Gross
2006-Jul-25 19:38 UTC
[Rails] Re: Re: Re: Re: Re: Problem getting form_remote_tag to work
Hey Ezra,
That didnt fix it, but I narrowed the problem down.
Basically in my partial I have
<% @pictures.each do |picture| %>
<div class="thumb_frame">
<%= ''<img class="photo thumb"
onmouseover="bringFront(this.id);"
onmouseout="sendBack(this.id);"
name="'' + picture.name + ''" id="'' +
picture.id.to_s + ''"
src="/images/pictures/thumbs/'' + picture.id.to_s +
''.jpg" />'' %>
<%= 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 <script>...</script> and putting it straight in
there but it gave me the same error.
--
Posted via http://www.ruby-forum.com/.
Eric Gross
2006-Jul-26 03:42 UTC
[Rails] Re: Re: Re: Re: Re: Problem getting form_remote_tag to work
Do any of you guys know why <script> 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? -- Posted via http://www.ruby-forum.com/.