I have a scenario that my user need to upload a image first and then
assign to another model, so I used a generic model, to upload the file
first. But I always get a exception of
ActiveRecord::UnknownAttributeError (unknown attribute: utf8). because
rails automatically adds a utf-8 field for the form submit.
class AttachedImage < ActiveRecord::Base
belongs_to :attachable, :polymorphic => true
class CreateAttachedImages < ActiveRecord::Migration
create_table :attached_images do |t|
t.string :image_file_name t.string :image_content_type t.integer :image_file_size t.datetime :image_updated_at t.references :attachable, :polymorphic => true t.timestamps end
And the controller:
class AttachedImagesController < ApplicationController
@attched_image = AttachedImage.new(params) respond_to do |format| if @attched_image.save format.js else format.js end end
the view part:
it’s quite straight forward, but every time I submit this form, I will
get an exception of the utf8 field added automatically by rails.
ActiveRecord::UnknownAttributeError (unknown attribute: utf8):
I could not understand that, this shall not be a problem right? We are
writing @model = Model.new(params) everyday, hope someone could help me
out and explain what’s going on under the hood, thanks!