Forum: Ruby on Rails Immediate help needed

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
88617b8c1550757f36cb71304b3d7d43?d=identicon&s=25 Jp (Guest)
on 2006-04-26 14:38
I have posted this previously also but haven't received any help.
So, if somebody could look into it and guide..
I want to validate the extension of files that I am uploading.
Like I want only the doc/pdf files to be uploaded..

Thanks in advance.
Ad7805c9fcc1f13efc6ed11251a6c4d2?d=identicon&s=25 Alex Young (Guest)
on 2006-04-26 14:51
(Received via mailing list)
Jp wrote:
> I have posted this previously also but haven't received any help.
> So, if somebody could look into it and guide..
> I want to validate the extension of files that I am uploading.
> Like I want only the doc/pdf files to be uploaded..
I believe this page may be of assistance:

http://wiki.rubyonrails.com/rails/pages/HowtoUploadFiles

It mentions that the action gets passed an object which has (among other
things) a content_type() method.
Fb23bc8cd4030c526b0689276b34c8bd?d=identicon&s=25 Bryan Duxbury (bryanduxbury)
on 2006-04-26 14:51
Jp wrote:
>
> I have posted this previously also but haven't received any help.
> So, if somebody could look into it and guide..
> I want to validate the extension of files that I am uploading.
> Like I want only the doc/pdf files to be uploaded..
>
> Thanks in advance.

Regular expressions.

if filename =~ /(\.doc|\.pdf)$/
  #accept the upload
else
  #discard file
end

(That regular expression I wrote is probably not perfect. Look around
for better examples)
5f3d7eb9e9314f4eb94b4040cee4d8d2?d=identicon&s=25 Vince Puzzella (Guest)
on 2006-04-26 16:41
(Received via mailing list)
Hi Folks,

I just noticed something odd with observe_form after updating from rails
1.0.0 to 1.1.2

It seems as though the first form field is always omitted from the ajax
request parameters. However, the request does contain an entry like
this:
"Form.serialize(\"some_form\")"=>"some_model[the_first_form_field]=some_valu
e"

My call to observe_form produces the following javascript:

new Form.EventObserver('some_form', function(element, value) {new
Ajax.Request('/some_model/some_action', {asynchronous:true,
evalScripts:true,
onComplete:function(request){eval(request.responseText)},
parameters:'Form.serialize("some_form")=' + value})})

Has anybody experienced similar behavior?
5922960cc4531f8df5774c5ba0b13d55?d=identicon&s=25 Craig Mason (Guest)
on 2006-04-27 01:46
Yes, I have noticed the exact same thing. Here's the hack/workaround
that works for me:

Change the observe_form call to include:
:with => "foo = Form.serialize('some_form')"

The "foo = " causes rails to lop off that extraneous '=' at the end.

Cheers,
Craig

Vince Puzzella wrote:

> I just noticed something odd with observe_form after updating from rails
> 1.0.0 to 1.1.2
>
> It seems as though the first form field is always omitted from the ajax
> request parameters. However, the request does contain an entry like
> this:
> "Form.serialize(\"some_form\")"=>"some_model[the_first_form_field]=some_valu
> e"
>
-snip-
> Has anybody experienced similar behavior?
5f3d7eb9e9314f4eb94b4040cee4d8d2?d=identicon&s=25 Vince Puzzella (Guest)
on 2006-04-27 16:47
(Received via mailing list)
Any takers?
5f3d7eb9e9314f4eb94b4040cee4d8d2?d=identicon&s=25 Vince Puzzella (Guest)
on 2006-04-27 17:30
(Received via mailing list)
Hi Folks,
I developed a realtime form validation plugin.  It uses AJAX to validate
from data on the fly.

The DOM is dynamically modified as the user enters form data. Form
fields
are wrapped with span elements which can be styled using CSS.

See the readme.txt file for more info.

You can get it here: http://rubyforge.org/projects/railsrtv/
This topic is locked and can not be replied to.