I need to write code that enables a user to upload a photo or csv file from their computer to the folder on the server through my rails app. Im a newbie and have been looking at tutorials online to do this. There are many approaches I have seen, so Im not sure which would be best for my situation:
In my app, there would be different types of users, such as visitors, members, administrator.
Only member and administrator should have the ability to upload files. I haven’t implemented authentication as yet, but will do this eventually. Im trying to understand what are the controllers and models in this scenario:
I was thinking:
1) Member model, Member_controller and member View
2) Administrator model, administrator_controller and administrator view
Since the function to manage files is common to both, where would that go?
Do I need a file_upload model, file_upload_controller and file_upload view?
Any tutorials that are similar to this scenario? Seems like a very common thing….I couldn’t find much on it.
I would actually create just one model, Member, and gives it an attribute to distinguish different types of users – including Admin. I would keep it simple.
Also, I would recommend Paperclip for handling file uploads.
https://github.com/thoughtbot/paperclip
Even if you go with two separate entities (Member and Admin), it would be easy for you to plug in the file upload capability to them.