File upload Rails Custom - ruby-on-rails

I am wondering how can i upload my file. I am have read this http://guides.rubyonrails.org/form_helpers.html#uploading-files but not to sure how to read and write the data from the controller? I also read this http://www.tutorialspoint.com/ruby-on-rails/rails-file-uploading.htm but placing them both together confused me. I don't like gem has i don't understand where the coded is stored, and doesn't allow flexibility in term of me able to write code specific to my application. Any help is appreciated

I would suggest using the Paperclip gem. The documentation is very straight forward and explains each of the steps in the file upload process.

Related

Rails, How does copycopter scan views for translations?

Can anyone point me to the code that CopyCopter uses to scan views for translations?
I considered using CopyCopter as my i18n back end but it has proved too problematic to upgrade it to Rails 4, perhaps when I have more time I'll have a go; So I have chosen to use the tolk gem (https://github.com/tolk/tolk) which is great but it relies on the main yml file to be maintained. This is not an option as there are non technical people working on adding new text plus there will be too many keys to be able to maintain yml files manually.
So I need a tool that will scan views for translation erb tags, check if there is a corresponding tag in the main yml file and add it if one does not exist.
It is my understanding that copycopter has functionality that scans views in this way and I thought I could rip the code out and adapt it for my needs but I have been unable to find the code in either the client (https://github.com/copycopter/copycopter-ruby-client) or the server (https://github.com/copycopter/copycopter-server).
I really want to avoid providing a web interface to manually add keys. That would be too open to mistakes as there will be likely over 8,000 keys.
Any help appreciated or alternative suggestions.
I have found a solution with the i18n-missing_translations gem https://github.com/svenfuchs/i18n-missing_translations. I need to do a bit of work to make them play nicely together but all should be good.

Gems/plugins for uploading multiple files in rails?

Specifically, I would like to allow a user to upload up to 5 images. Any direction to a simple tutorial would be greatly appreciated. Ideally the data for the uploaded file would be stored in an existing database. I have tried paperclip, but I can't seem to get it to work with multiple files. I've also tried some other tutorials from 2008 that don't seem to work w/ rails 3.Thanks for the help!
I would prefer direction of tutorials that you have tried and worked.
Since I had the same problem yesterday, I wrote a tutorial about it: http://blog.powpark.com/2013/10/16/multiple-file-upload-with-html5-and-rails-admin/
I think one of the most popular file-upload gems is Carrierwave (https://github.com/carrierwaveuploader/carrierwave). There is also a demo app (https://github.com/kdironside/carrierwave-multi-file-upload) that specifically demonstrates uploading multiple files.
However, it's certainly possible to accomplish the same thing with Paperclip. Perhaps you can let us know what problem you ran into specifically, and we can help you out there.

Rails - Given a File Form Posted, How to Store in the DB and then Read later?

Given a Rails Form Post with X number of files.
How do you store the file in the Database?
Then, later, how do you then read the file?
Thanks.
A little more background. The file form post is from SendGrid's parse api. Then later I want to be able to read the file with delayed_job and then use paperclip to store the file and process it on S3.
Thanks
Pretty sure I just answered your other question the same way: https://github.com/jstorimer/delayed_paperclip does what you seem to want it to do.
Based on the limited information I know about your system, I'm assuming you've got some model that tracks the emails. That's a good start.
First I would like to clarify that in no situation should you be storing files in the database. Files go in the filesystem, where they can be read and written much faster.
Now with that in mind, I would have a model that associates with your email model, possibly called Part. This model's purpose will be to use Paperclip to store the files. I would call the attachment part also, and so to create a new one you would do this:
email.parts.build(:part => some_file)
In that case, Paperclip will take care of moving the file to where it needs to be. To read the file later, Paperclip has methods for that. Check out Paperclip's documentation, it's pretty good for this sort of thing.

How do I add file uploads to a rails app?

I need to add the ability to upload and store any kind of file, PDF, XLS, DOC, etc. What is the best way to do this in a ruby on rails application?
I think this is exactly what you're looking for.
Upload files.
I'd recommend you to use paperclip or carrierwave both are really good libs and work out of the box in most cases.
you can also look at attachment_fu rails.
I've worked with two of the big players when it comes to file uploads. carrierwave and paperclip.
They provide a good solution for a common task with support for different storage alternatives. Both support filesystem and S3. Carrierwave also supports Rackspace Cloud Files and MongoDB’s GridFS.
I would recommend carrierwave because of one aspect where they are different to use. It uses a separate upload class that you mount on your model. This separates your code related to the file upload from the model code. I find this approach cleaner and easier to test.

Storing documents using Ruby On Rails

I would like users of my ruby on rails app to be able to upload documents (Word Documents, Spreadsheets, PDFs, etc). What is the best way of doing this?
I've used file_column, attachment_fu, and paperclip. I've also had to dive into the source on all three plugins.
Without a doubt, I recommend paperclip above the others. The source is easier to read and understand. Its easier to extend. It doesn't do extraneous file copies.
Go with paperclip and let us know if you have any questions.
"Best" depends on your exact needs, but have a look at PaperClip. It's a pretty easy way to integrate files with ActiveRecord.
I agree that Paperclip is the best solution currently available.
If you decide to use Paperclip, you might want to take a look at this question which discusses how to display thumbnails for non-image types (.doc, .xls etc).
Set path for original images using paperclip in Rails?

Resources