Forum: Ruby on Rails Uploaded File to Database

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
C11579192bd480035b95d6cc82a79907?d=identicon&s=25 Dieter Komendera (Guest)
on 2006-03-06 21:00

I currently write a tool for my school. Therefore I have to save
uploaded files.
I bought Agile Web Dev. with Rails to learn webdev with Rails.
I'm very new at rails and couln'd find anything on the internet.

Now when I want to save the file data to the mysql database, rails gives
me an error.
My code is the same as written in the book on page 363.

Here is my code of the model:

class Document < ActiveRecord::Base
   has_many :comments
     def file=(file_field)
       self.filename = base_part_of(file_field.original_filename)
       self.content_type = file_field.content_type.chomp =
     def base_part_of(file_name)
       name = File.basename(file_name)
       name.gsub(/[^\w._-]/, '')

The data column in the database is blob

the file seems to be uploaded correctly, but something goes wrong.
I get this error message:

ActiveRecord::StatementInvalid in Admin#create

Mysql::Error: You have an error in your SQL syntax near
at line 1:

I assume the long number is the binary data of the file.
The part of question in the query string is this:

... 'filename.ext', x'3c3f786d6c2076657273696f ...

When copy the whole query string from the error message into a text
editor, delete the x after the comma, paste the string then into
phpMyAdmin and execute it, everything goes well.

If I omit saving the data, everything goes well.

Addtional info:
Rails version: 1.0.0
MySQL version: 3.23.58

So what can I do, to force Rails to do not write the x into the query
Or what else can I do?

Dieter Komendera
Ad7805c9fcc1f13efc6ed11251a6c4d2?d=identicon&s=25 Alex Young (Guest)
on 2006-03-06 23:09
(Received via mailing list)
Dieter Komendera wrote:
> MySQL version: 3.23.58
> So what can I do, to force Rails to do not write the x into the query
> string?
I believe this link may be relevant:

> Or what else can I do?
Upgrade to a more recent version of MySQL.
This topic is locked and can not be replied to.