I am running Rails 3.2.17 and Postgres 9.3.4. I created a new ActiveRecord model using \"rails generate\" and one of the column types is json. My intention is to use the jso
Change your migration like
class CreateThing < ActiveRecord::Migration
def change
create_table :things do |t|
t.integer :user_id
t.column :json_data, :json # Edited
t.timestamps
end
add_index :things, :user_id
end
end
And by default rake db
tasks will look into schema.rb( which wont be the case for postgres) so in application.rb change it to
config.active_record.schema_format = :sql
Set the following in application.rb
config.active_record.schema_format = :sql
Then structure.sql will be used instead of schema.rb to create the database from scratch. More info - https://github.com/diogob/activerecord-postgres-hstore
We have a legacy application that uses activerecord-postgres-json to add json
and jsonb
type support to ActiveRecord in Rails 3.2; it may be an option if you're stuck at a low Rails version.