Here is the current basic information:
new (views/file_uploads/new.html.erb)
<% form_for( @file_upload, :html => { :multipart => true } ) do |f| %>
<%= f.error_messages -%>
<%= f.label :upload, 'File' -%> <%= f.file_field :upload -%>
<%= f.submit( 'Upload' ) %>
<% end %>controller
def new
@file_upload = FileUpload.new
end
def create
@theme_upload = FileUpload.new(params[:upload])
respond_to do |format|
if FileUpload.save
flash[:notice] = ‘Successfully Uploaded File.’
format.html { redirect_to(@file_upload) }
else
format.html { render :action => “new” }
end
end
end
model
class FileUpload < ActiveRecord::Base
validates_presence_of :upload
attr_accessor :upload
end
yaml file being uploaded
file:
name: default
author: First L.
date: 2010-01-01
stylesheets: true
javascripts: true
layouts: true
swfs: true
=================
What I would like to be able to do is eventually upload a number of file
folders with files based off what is listed in a YAML file being
selected and read.
For instance, if I could info = YAML.load_file(the_path_to_upload_file)
I would get the following:
=> {“file”=>{“name”=>“default”, “date”=>Fri, 01 Jan 2010,
“author”=>“First L.”, “swfs”=>true, “javascripts”=>true,
“layouts”=>true, “stylesheets”=>true}}
and would be able to read/use the information later on.
My problem is understanding how to call/access that information using
the template above. If I run it right now, of course what will happen
is a record will be saved with nil information because nothing is truly
being sent/saved properly.
However, when viewing it in the console, the following information is
being sent via parameters:
Parameters: {“commit”=>“Upload”,
“authenticity_token”=>“4IW8zdd8WyHFBjxMJgxZbPtPp0XlJiPInxtlywfaf74=”,
“file_upload”=>{“upload”=>#<File:C:/Users/MyUser/AppData/Local/Temp/RackMultipart.3076.2>}}
If I open the Rackmultipart.3076.2 file it does match the exact same
contents of the yaml file being uploaded.
Again, I’m unsure of how to go about defining a method to simply read
the yaml file and parse its contents using an upload button.