我跟隨Ryan Bates的Rails 4的第400集的Railscasts http://railscasts.com/episodes/400-what-s-new-in-rails-4的預覽。他設置了使用postgres(我已經安裝)和hstore的演示程序。他創造這樣未定義的方法`hstore'爲活動記錄
rails g scaffold article name content:text published_on:date tags properties:hstore
支架,並在遷移做到這一點
execute "create extension hstore"
create_table :articles do |t|
t.string :name
t.text :content
t.date :published_on
t.string :tags, array: true
t.hstore :properties
t.timestamps
end
然而,當我跑這個遷移我得到了一個未定義的方法「hstore」的錯誤。然後我走進我的測試數據庫,當你看到下面創建hstore擴展(而不是在遷移文件瑞恩一樣)
psql rails4test2_development
psql (9.2.3)
Type "help" for help.
rails4test2_development=# CREATE EXTENSION hstore;
但我得到了同樣的錯誤,當我跑遷移。
undefined method `hstore' for #<ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::TableDefinition:0x007fa7ee7a9138>/Users/me/Sites/rails4test2/db/migrate/20130511204911_create_articles.rb:9:in `block in change'
/Users/me/Sites/rails4test2/db/migrate/20130511204911_create_articles.rb:4:in `change'
誰能幫我明白爲什麼這不是爲我工作?
@GoGoGarrett,我不是回答你期待的類型完全確定;快速搜索'hstore'列方法或從[Rails 3.2.19]中獲取以下兩個文件(https://github.com/rails/rails/blob/v3.2.19/activerecord/lib/active_record/connection_adapters /postgresql_adapter.rb)和[Rails 4.2.0beta1](https://github.com/rails/rails/blob/v4.2.0.beta1/activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb)顯示方法在最新的Rails 3中未定義。 – vee 2014-09-10 00:08:54