params[] element not passed into new object in create action
I have a very simple form, with the scaffold controller action. the DB schema for the relevant is as follows:
create_table "uploads", :force => true do |t|
t.string "name"
t.string "location"
t.string "type"
t.datetime "created_at"
t.datetime "updated_at"
t.string "filename"
end
When the form is submitted, the params contains the following (look at the specific typ开发者_JAVA技巧e parameter):
{"utf8"=>"✓",
"authenticity_token"=>"NGV4rS/tZDWg2ZdMLpiSbTJQBDmMyjfYyZqZ6GX/7Kc=",
"upload"=>{"name"=>"AEGFAEF",
"type"=>"Sales",
"file"=>#<ActionDispatch::Http::UploadedFile:0x4dff958 @original_filename="Google.pdf",
@content_type="application/pdf",
@headers="Content-Disposition: form-data; name=\"upload[file]\"; filename=\"Google.pdf\"\r\nContent-Type: application/pdf\r\n",
@tempfile=#<File:C:/Users/kaya/AppData/Local/Temp/RackMultipart20110602-2876-1wyskk3>>},
"commit"=>"Create Upload"}
the first command in the create action of UploadsController is
@upload = Upload.new(params[:upload])
and right after this line I have
@upload.type = nil
I really don't get how such a basic thing is failing. can someone please give a hand?
thanks a bunch in advance.
In rails type
is a MagicFieldName and it is reserved for table inheritance. Since in your case Upload
doesn't inherit from anything, querying type
on an object will return nil.
It is known that using MagicFieldNames as columns names causes lots of troubles. You can check http://oldwiki.rubyonrails.org/rails/pages/MagicFieldNames for a full list.
"Rails values convention over configuration. This is also true in the realm of table design where fields given particular names automatically gain certain behaviours.
Active Record allows inheritance by storing the name of the class in a column that by default is called “type” (can be changed by overwriting Base.inheritance_column)."
Column 'type' is reserved for STI. I dont know if you are using it. If don't, change 'type' to another name.
精彩评论