Reputation: 39
I am a beginner with Ruby on Rails but am trying to create my own application.
I've added users and a few models but am stuck on something.... I am trying to create a model called 'JOBS' with the following items:
Im not sure how to get the file upload form in there...
If someone can point me in the right direction it would be greatly appreciated.
Upvotes: 1
Views: 72
Reputation: 1670
If you are uploading to Amazon S3 i found that using the Paperclip gem was pretty straight forward.
Here is a walkthrough from Heroku: https://devcenter.heroku.com/articles/paperclip-s3
Upvotes: 0
Reputation: 35443
I recommend you try the CarrierWave gem.
The docs are excellent, and show you how to create an upload form. CarrierWave is what many Rails professionals choose to use because it offers many conveniences, ways to upload multiple files at once, multiple backend storage systems such as Amazon S3, etc.
For example, you could write a job that has a title and image like this:
class ImageUploader < CarrierWave::Uploader::Base
storage :file
end
class Job < ActiveRecord::Base
mount_uploader :image, ImageUploader
end
Alternatively, if you're interested in learning how to do it in Rails without any gem, then read the Rails guides on form helpers for uploading files
For example, you could write a form that has a job title and image like this:
<%= form_for @job do |f| %>
<%= f.text_field :title %>
<%= f.file_field :image %>
<% end %>
Upvotes: 1