Hello i am trying to save some data to my db, this is what i got:
MODEL:
class File < ActiveRecord::Base
belongs_to :product
def uploaded_file=(picture_field)
self.name = base_part_of(picture_field.original_filename)
self.content_type = picture_field.content_type.chomp
self.data = picture_field.read
end
def base_part_of(file_name)
File.basename(file_name).gsub(/[^\w._-]/, '''')
end
end
CONTROLLER:
def create
@product = Product.new(params[:product])
@product.save
for file in params[:file]
@file = File.new(params[:file])
@file.producto_id = @producto.id
@file.save
end
if @product.save
flash[:notice] = ''Product created.''
redirect_to :action => ''list''
else
render :action => ''new''
end
end
VIEW:
i render a partial, and tis is the partial:
<%= error_messages_for(:product)%>
<!--[form:producto]-->
<p><label for="product_name">Name</label><br/>
<%= text_field ''product'', ''name''
%></p>
<p><label
for="product_description">Description</label><br/>
<%= text_area ''product'', ''description''
%></p>
<!--[eoform:producto]-->
<fieldset>
<legend>Image</legend>
<% fields_for "file[]" do |f|%>
<p><label for="product_file">File:
</label><br/>
<%= f.file_field :uploaded_file %></p>
<%end%>
</fieldset>
<fieldset>
<legend>Pdf</legend>
<% fields_for "file[]" do |f|%>
<p><label for="product_file">File:
</label><br/>
<%= f.file_field :uploaded_file %></p>
<%end%>
</fieldset>
When i try to save i got this error:
undefined method `keys'' for #<Array:0x482bbf4>
RAILS_ROOT: ./script/../config/..
Application Trace | Framework Trace | Full Trace
#{RAILS_ROOT}/app/controllers/admin/product_controller.rb:30:in
`create''
-e:4:in `load''
-e:4
Parameters:
{"product"=>{"description"=>"asdfasdfasd",
"name"=>"aasfasdf"},
"file"=>[{"uploaded_file"=>#<File:C:/Windows/Temp/CGI.5992.3>},
{"uploaded_file"=>#<File:C:/Windows/Temp/CGI.5992.4>}],
"commit"=>"Create"}
Response
Headers: {"cookie"=>[],
"Cache-Control"=>"no-cache"}
helps plis :P, regards
--
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---