# Immediate help needed

**URL:** <https://www.ruby-forum.com/t/immediate-help-needed/58844>\
**Category:** Rails\
**Created:** [April 26, 2006, 2:38pm UTC](https://www.ruby-forum.com/t/immediate-help-needed/58844 "2006-04-26T14:38:52Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 26, 2006, 2:38pm UTC](https://www.ruby-forum.com/t/immediate-help-needed/58844/1 "2006-04-26T14:38:52Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 26, 2006, 2:51pm UTC](https://www.ruby-forum.com/t/immediate-help-needed/58844/2 "2006-04-26T14:51:40Z")

</div>

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](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.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 26, 2006, 4:41pm UTC](https://www.ruby-forum.com/t/immediate-help-needed/58844/3 "2006-04-26T16:41:58Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 27, 2006, 1:46am UTC](https://www.ruby-forum.com/t/immediate-help-needed/58844/4 "2006-04-27T01:46:56Z")

</div>

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 P. 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?

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 27, 2006, 4:47pm UTC](https://www.ruby-forum.com/t/immediate-help-needed/58844/5 "2006-04-27T16:47:56Z")

</div>

Any takers?

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 27, 2006, 5:30pm UTC](https://www.ruby-forum.com/t/immediate-help-needed/58844/6 "2006-04-27T17:30:43Z")

</div>

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/](http://rubyforge.org/projects/railsrtv/)

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 26, 2006, 2:51pm UTC](https://www.ruby-forum.com/t/immediate-help-needed/58844/7 "2006-04-26T14:51:55Z")

</div>

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)
