File upload content types on Ruby on Rails one-liner
Need to save the content_type of a file upload in Ruby on Rails? Here’s a simple one-liner for your model that does it:
self.content_type = incoming_file.content_type.to_s.strip!
where incoming_file is a reference to the file that’s been uploaded. Why the strip! call? Because Rails (at least on Windows) stores an extra character (newline / carriage return) at the end of the content_type field. strip! (the bang method) drops that last character in place, letting you do everything in that single line.
technorati tags:rubyonrails, file, upload, ror