Reputation: 11
Ruby on Rails 4.0
I have item model. Item new form has image field that does not exist on DB. Because I want to save files on directory.
But how can I make validation for file field?
Upvotes: 0
Views: 228
Reputation: 3067
You could add an attr_accessor
to your model.
class Item < ActiveRecord::Base
attr_accessor :file
validates_presence_of :file
end
Then in the form
<%= f.file_field :file %>
That is one option but I would recommend looking into using Carrier Wave or Paperclip for file uploads. The files are still saved on the file system and are only referenced in the database by their file names.
Upvotes: 2