Uploading a File to a Website with Ruby/Rails

Uploading Rails to a website

You should write Capistrano script for deployment. This is recommended way at present for deployment Rails applications to remote servers.

But this is not a one way to do it. So, you can use other approaches i.e. build and deploy Docker containers or copy sources over FTP manually (this is not recommended but possible way).

How to publish and implement Ruby file to my website

If you are using the rails framework you may wanna try using cloud9 instead. Brackets from what i understand is "local". Whereas cloud9 is a "real" IDE. Additionally you can easily push your code to heroku where your code will be hosted at.

To get things started just head over to cloud9 to create an account to setup your IDE. If you are unfamiliar with it there are lots of guides out there that can help you to get things started.

However if you lack the fundamentals in using the rails framework, guides.rubyonrails.org may be a good place to start too.

Update:
There is no best language when it comes to developing a website. The fundamentals of a webpage are HTML/CSS.

HTML gives you the bones or structure, such as your titles and your paragraphs etc.

CSS gives you your styling, such as creating buttons or changing font color etc.

This 2 languages form the core part of what would be your website, at the very least on the front end (meaning to say what people see when they visit your website)

JavaScript is not a must but definitely a plus. It is able to improve the UI/UX (user interface/user experience) of your website.

Lastly would be your back-end language; what handles the processes that goes on behind the scenes. If you choose ruby (and by extension rails) then that is fine as well. Basically your back-end language will support your database and CRUD (create, read, update, delete) actions.

Uploading a file in Rails

Update 2018

While everything written below still holds true, Rails 5.2 now includes active_storage, which allows stuff like uploading directly to S3 (or other cloud storage services), image transformations, etc. You should check out the rails guide and decide for yourself what fits your needs.


While there are plenty of gems that solve file uploading pretty nicely (see https://www.ruby-toolbox.com/categories/rails_file_uploads for a list), rails has built-in helpers which make it easy to roll your own solution.

Use the file_field-form helper in your form, and rails handles the uploading for you:

<%= form_for @person do |f| %>
<%= f.file_field :picture %>
<% end %>

You will have access in the controller to the uploaded file as follows:

uploaded_io = params[:person][:picture]
File.open(Rails.root.join('public', 'uploads', uploaded_io.original_filename), 'wb') do |file|
file.write(uploaded_io.read)
end

It depends on the complexity of what you want to achieve, but this is totally sufficient for easy file uploading/downloading tasks. This example is taken from the rails guides, you can go there for further information: http://guides.rubyonrails.org/form_helpers.html#uploading-files

Rails: upload a file OR store a url

What I will probably do is to have a drop down in the file upload form to select if the file is from the disk or from external url.

By default it will set to "from disk", and if they select external url, you could use some AJAX magic and hide the file upload text box and have a text box to use the external url/script etc..

in the table, you can keep another two columns,

1 - external url

2 - file category (external / uploaded file)

by that way you can distinguish the files and how they what to display in the view

HTH

Uploading/Downloading files - Ruby On Rails system

You should look at Paperclip gem https://github.com/thoughtbot/paperclip

It is very easy to use and allows to upload files.

How to upload a file in rails?

Usually gems/plugins are used to to handle file uploads. My favorite one, and perhaps the most ubiquitous is Paperclip.

In your view, you'll have to tell the rails form helpers that you're uploading a file like this:

<%= form_for @model, :html => { :multipart => true } do |form| %>

Upload files from folders and sub-folders to webapp

I would recommend creating an Adobe Air app.

You can reuse your existing plupload js code, and extend it with adobe air apis. Ideally, it would be a mostly static app but make a server call to create the policy document, and do any book-keeping you want to do on the uploads. Take a peak at Accessing AIR API classes from JavaScript. Then look into the filesystem.File class.

Flash has something like a 99.3% penetration, and with it the user just clicks "Install My Uploader" and the air framework is automatically installed if needed. Air is also on Android and iDevices, so your app would probably be available to 99.999% of users and their moms.

It took me a minute to find it, but here is the Adobe® AIR® API Reference for HTML Developers

Oh look what I found in their examples:

var directory = air.File.documentsDirectory;

try
{
directory.browseForDirectory("Select Directory");
directory.addEventListener(air.Event.SELECT, directorySelected);
}
catch (error)
{
air.trace("Failed:", error.message)
}

function directorySelected(event)
{
directory = event.target ;
var files = directory.getDirectoryListing();
for(var i = 0; i < files.length; i++)
{
air.trace(files[i].name);
}
}


Related Topics



Leave a reply



Submit