문제

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
도움이 되었습니까?

해결책 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

다른 팁

Mostly for those who find this later...may also need to whitelist new params in interested controllers

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top