缩进的问题没这么严重吧,难道写 erb 会不缩进?
#15 楼 @Ddl1st 木有新加的 filed 的,跟之前通过 robomongo 连过去 mongodb 看的一样。
zhangner@elementary:~/workspace/concern$ rails c
Loading development environment (Rails 4.0.0)
1.9.3p392 :001 > News.fields.keys
=> ["_id", "created_at", "updated_at", "tags_array", "title", "category", "subcategory", "from", "reference", "summary", "content"]
1.9.3p392 :002 >
#10 楼 @Ddl1st 看着是 development 的
zhangner@elementary:~/workspace/concern$ rails c
Loading development environment (Rails 4.0.0)
1.9.3p392 :001 >
zhangner@elementary:~/workspace/concern$ rails s
=> Booting Thin
=> Rails 4.0.0 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
>> Thin web server (v1.5.1 codename Straight Razor)
>> Maximum connections set to 1024
>> Listening on 0.0.0.0:3000, CTRL+C to stop
rake db:mongoid:purge
把整个 collections drop 掉重新创建都不成了,mongodb 里边新创建的记录还是没后面加的 likes 和 dislikes 这两属性。
include Mongoid::Document
include Mongoid::Timestamps
include Mongoid::Taggable
paginates_per 20
field :title
field :category
field :subcategory
field :likes, type: Integer, default: 0
field :dislikes, type: Integer, default: 0
field :from
field :reference
field :summary
field :content
index({ title: 1 })
index({ category: 1})
zzzzz
自己顶下别沉了,求指点。
视频这会肯定是木有的,因为用的公司设备录制的,昨晚设备还公司了,视频没拷出来。
#2 楼 @lidashuang 同时如果取到的记录是 group 实例,从中取 topics 的时候也会有 N+1 查询,这时要对这查询怎么做 Eagar Loading 呢?
#1 楼 @huacnlee 简单点就是有下面几个 Model 和关系
class Action < ActiveRecord::Base
belongs_to :actionable, :polymorphic => true
end
class Book < ActiveRecord::Base
has_one :action, :as => :actionable
has_many :items
end
class Group < ActiveRecord::Base
has_one :action, :as => :actionable
has_many :topics
end
然后通过下面的查询从 Action 中取记录,
Action.includes(:actionable).where("created_at < ?", Time.now).limit(50)
通过 Polymorphic 取到各个关联的 Model,比如有条记录是一个 book 实例,要从这个 book 实例中取 items 的时候产生了 N+1 查询。
1.Gemfile 中使用的 mysql 的 gem 不会是 mysql2 吧? 2.ruby/bin/下面的libmysql.dll版本是ok的?gem install mysql 的时候会有提示的