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. -- Posted via http://www.ruby-forum.com/.
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 On 3/13/06, John Petterson <john.petterson@gmail.com> wrote:> > 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. > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- "Do not meddle in the affairs of dragons, for you are crunchy and good with ketchup." -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060313/9ed1ae4e/attachment-0001.html
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 Merrell 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-- Posted via http://www.ruby-forum.com/.
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 On 3/13/06, John Petterson <john.petterson@gmail.com> wrote:> > 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 Merrell 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 > > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- "Do not meddle in the affairs of dragons, for you are crunchy and good with ketchup." -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060314/ebfea52d/attachment-0001.html
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 Merrell 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-- Posted via http://www.ruby-forum.com/.