attr_accessor :ext, :d_create, :l_mod
remove this line from your model and try again.
Now you have these attributes in DB so Rails will do this job automatically
Question
I recently added new columns to my database (sqlite) for Media and it shows that the columns are inserted, but the new columns will not update on Medium.new
My original database:
class CreateMedia < ActiveRecord::Migration
def change
create_table :media do |t|
t.string :name
t.string :location
t.timestamps
end
end
end
These columns update on Media.new
class AddMetaToMedia < ActiveRecord::Migration
def change
add_column :media, :ext, :string
add_column :media, :l_mod, :string
add_column :media, :d_create, :string
end
end
and I am calling
Medium.new(name: f, location: str, ext: ex)
ext will not update to ex = File.extname(f), which I know has a value through print statements/console. Am I calling Medium.new wrong? Why is it updating name and location but not the new columns?
edit: Here is my model, I've tried with and without attr_accessible/attr_accesor
class Medium < ActiveRecord::Base
attr_accessor :ext, :d_create, :l_mod
end
La solution 2
attr_accessor :ext, :d_create, :l_mod
remove this line from your model and try again.
Now you have these attributes in DB so Rails will do this job automatically
Autres conseils
Mostly for those who find this later...may also need to whitelist new params in interested controllers