I would like to use the ruby on rails and mysql to write a simple test program but, in this time, i can not update the database record. because i use the "mid" to replaced the "id" column in this case, what can i do to work to update the record?
Problem:
Mysql::Error: Unknown column 'id' in 'where clause': UPDATE `messages` SET `message` = 'ccc', `subject` = 'aaa', `author` = 'bbb' WHERE `id` = NULL
My Code:
def update
@message = Message.find(:first, :conditions => ["mid = ?", params[:id]])
if @message.update_attributes(params[:message])
flash[:notice] = 'Post was successfully updated.'
redirect_to gbook_path(:id => @message.mid)
else
format.html { render :action => "edit" }
end
end
Database:
CREATE TABLE `demo_development`.`message` (
`mid` MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`subject` VARCHAR( 30 ) NOT NULL ,
`author` VARCHAR( 30 ) NOT NULL ,
`message` TEXT NOT NULL ,
`adddate` INT UNSIGNED NOT NULL
) ENGINE = MYISAM ;