Chapter 9. File uploading

 

This chapter covers

  • Uploading files to the app
  • Locking down file access based on declared permissions
  • Uploading multiple files using JavaScript, jQuery, and CoffeeScript

In chapter 9, you learned how to restrict access to specific actions in your application, such as viewing projects and creating tickets, by defining a Permission model that keeps track of which users have access to which actions.

Ticketee’s getting pretty useful now. This chapter focuses on file uploading, the next logical step in a ticket-tracking application. Sometimes, when people file a ticket on an application such as Ticketee, they want to attach a file to provide more information for that ticket, because words alone can only describe so much. For example, a ticket description saying, “This button should move up a bit,” could be better explained with a picture showing where the button is now and where it should be. Users may want to attach any kind of file: a picture, a crash log, a text file, you name it. Currently, Ticketee has no way to attach files to the ticket: people would have to upload them elsewhere and then include a link with their ticket description.

By providing Ticketee the functionality to attach files to the ticket, you provide the project owners a useful context that will help them more easily understand what the ticket creator means. Luckily, there’s a gem called Paperclip that allows you to implement this feature easily.

9.1. Attaching a file

9.2. Attaching many files

9.3. Serving files through a controller

9.4. Using JavaScript

9.5. Summary