I want to modify following code in order to be able to write only the file extension into a database. Now I read the file_content_type, but I need only to know the extension (it doesn’t matter for me that the extension can be changed) and to put it into a database.
upload_file_name has an extension already, but I need to extract it and put it in the same database-table as a new row.
ActiveRecord::Schema.define(:version => 20120731045929) do
create_table "uploads", :force => true do |t|
t.string "upload_file_name"
t.string "upload_content_type"
t.string "user"
t.integer "upload_file_size"
t.datetime "upload_updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
end
And it is possible somehow to save the file_name without an extension?
That looks like it’s from
schema.rb.Don’t touch that one directly.
If you look under
/db/migrationsyou’ll have ruby files with messy looking file names. These are the ruby files that let you configure your database tables.In the terminal, run
rails generate migration add_file_content_type_to_uploads file_content_type:stringfile_content_typeto attr_accessibleattr_accessible :file_content_typeFile.extname.So maybe in your
createmethod of uploads controller