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)%>
Name
<%= text_field 'product', 'name' %>
Description
<%= text_area 'product', 'description' %>
File:
<%= f.file_field :uploaded_file %>
File:
<%= f.file_field :uploaded_file %>
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