Forum: Ruby on Rails Problem realted to upload..

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.
John P. (Guest)
on 2006-03-13 14:15
I want to upload a file.
And what I am confused about is...should I upload it using a separate
table or just as another file in the form.
If as a separate table then I am not able to save it on the system/
Or/ If not that, then how can i check for the extensions?
Do reply.
Thanks.
Rob M. (Guest)
on 2006-03-13 20:08
(Received via mailing list)
John,
Have you looked at the file_column plugin(
http://www.kanthak.net/opensource/file_column/)?  What do you mean by
using
a seperate table?  Are you trying to stick the file in the database or
by
table do you mean the reference to the file location?  As for the file
extension's I'm not exactly sure, the ruby File.ftype returns the type
of
the file which may be useful for you.  Otherwise you might be stuck
doing
some regex.

Rob
John P. (Guest)
on 2006-03-14 06:59
Thankyou Rob.
I'll try to be more explanatory.
Actually, I want to upload a file entered by the user using simple
"input file" option in the _form.rhtml code. And after that I want to
check for the right extensions. That is it needs to just upload the doc
file.
Doing this I am stuck up with the extension checking. Though its saving
everything in the /public/ file very comfortably.
Hoping to hear more.
Thanks once again.

Rob M. wrote:
> John,
> Have you looked at the file_column plugin(
> http://www.kanthak.net/opensource/file_column/)?  What do you mean by
> using
> a seperate table?  Are you trying to stick the file in the database or
> by
> table do you mean the reference to the file location?  As for the file
> extension's I'm not exactly sure, the ruby File.ftype returns the type
> of
> the file which may be useful for you.  Otherwise you might be stuck
> doing
> some regex.
>
> Rob
Rob M. (Guest)
on 2006-03-14 07:45
(Received via mailing list)
John,

Here's a regex that will strip out the extension of a filename.  What it
actually does is returns everything after a '.' is first encountered in
the
string, so: "filename.doc" would return "doc".

file_name = "my_file.ext"

regex = Regexp.new('\.(.*)$')
match_data = regex.match(file_name)
file_extension = match_data[1]

Hope that helps.

Rob
John P. (Guest)
on 2006-03-14 08:52
Rob,
I tried using validates_format_of...
But didn't not get the desired results, what i actually did was...

validates_format_of :user_file,
                        :with => %r{.(doc|pdf)$}i,
                        :message => "please"
But gives me

undefined method `user_file' for #<User:0xb768a07c>

If you could help. I am new to Ruby on Rails, so I might be sounding
silly too but hope you understand and would help.

Thanks.

Rob M. wrote:
> John,
>
> Here's a regex that will strip out the extension of a filename.  What it
> actually does is returns everything after a '.' is first encountered in
> the
> string, so: "filename.doc" would return "doc".
>
> file_name = "my_file.ext"
>
> regex = Regexp.new('\.(.*)$')
> match_data = regex.match(file_name)
> file_extension = match_data[1]
>
> Hope that helps.
>
> Rob
This topic is locked and can not be replied to.