Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class FileUpload < ActiveRecord::Base
- ###############################################
- ################# VALIDATIONS #################
- validates_presence_of :upload_file
- validates_format_of :upload_file,
- :with => %r{\.(pdf|jpg|png)$}i,
- :message => 'Must be a URL for PDF, JPG or PNG file.'
- def self.save(upload,id)
- name = upload.original_filename
- Dir::mkdir 'public/floorplans/' + id.to_s
- directory = "public/floorplans/" + id.to_s
- # create the file path
- path = File.join(directory, name)
- # write the file
- File.open(path, "wb") { |f| f.write(upload.read) }
- end
- end
- -------------------------------------------------
- # Controller
- #Uploading the file
- post = FileUpload.save(params[:upload_file],@floorplan.id)
- ---------------------------------------------------
- # view
- <% form_tag( {:controller => :floorplan, :action => :new, :id => @outlet.address }, :multipart => true) do %>
- <div>
- file: <input type="file" name="upload_file"> <br />
- <input value="Upload" type="submit">
- </div>
- <% end %>
Add Comment
Please, Sign In to add comment