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 -%>
<p>
<%= f.label :upload, ''File'' -%>
<%= f.file_field :upload -%>
</p>
<p><%= f.submit( ''Upload'' ) %></p>
<% 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 Last
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 Last", "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.
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
For instructional use here is what I see: 1. Admin user goes to form. 2. Admin user selects browse and finds the yaml file. 3. Admin users selects upload. 4. yaml file is read and parsed. 5. model saves the information from the yaml file into a record. 6. uploading begins in another routine based off what was recorded in step 5. I hope that helps... My problem is understanding what to do between steps 3 - 5. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Jan 12, 1:47 pm, Alpha Blue <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> 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 -%> > <p> > <%= f.label :upload, ''File'' -%> > <%= f.file_field :upload -%> > </p> > <p><%= f.submit( ''Upload'' ) %></p> > <% 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 Last > 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 Last", "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/RackMul tipart.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. > -- > Posted viahttp://www.ruby-forum.com/.Are you looking for local_path? As in YAML.load_file params[:file_upload][:upload].local_path ? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
pharrington wrote:> Are you looking for local_path? > > As in YAML.load_file params[:file_upload][:upload].local_path > ?Thanks mate - yes this is exactly what I was looking for. I have not done a lot of work with reading files and am becoming familiar with how to do certain things with them. I couldn''t figure out how to translate the local_path and now you showed me. Many thanks! -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.