不要发布盗版资源,我编辑掉了。
我觉得不用解决。
mail 这个 gem,smtp 协议。
15 分钟 demo 已经很久不提了,最新是 Rails is Omakase,早前是 Rails is not for beginers.
这下是代码注入了,比较严重。
#5 楼 @dreamable 首先,慎用继承,如果 model 或者 contorller 有重复的代码,可以抽取 Concern http://37signals.com/svn/posts/3372-put-chubby-models-on-a-diet-with-concerns
然后,Model 用了继承,Controller 不一定要继承,像 Ruby China 的消息通知(https://github.com/ruby-china/ruby-china/tree/master/app/models/notification)继承了同一个 model,但是 Controller 用的是同一个,一致的 read, destroy 行为。继承本来不就是让他们表现一样的行为么?消息通知用继承的原因是希望各类消息存在同一个集合。
至于 View,if 处理没问题,或者像 Ruby China 这样利用局部模板
<%= render :partial => "notifications/#{notification.class.name.underscore}", :locals => {:notification => notification} %>
第一种方式是已经被废弃的 rjs 代码,没有 page.replace_html 这个方法了,所以是跑不通的。
为了使用继承而使用继承?
这是前端逻辑,用 javascript 实现。
传统出版的弊端,每次印刷有个印量,根据销售情况加印。但在技术类书上,除非是热门书,不然都不会卖得很快,慢慢的后来的人就买不到了,出版社也不会加印。
既然什么想不到的词都能成为关键词,那就不要想了。
ActiveRecord
赞同 @reus ,简单最好。
我上午发过一个贴,现在这个状况也适合:疏忽大意的危险在于每个人都认为自己没有疏忽大意。没有摔过跤,就总会觉得悲剧不会在自己身上发生。我也是挂过一次服务器才养成了每日备份的意识。
想得美 XD
rework XD
多年以后,我们仍未知道 2012.12.21 那天之后 Ruby China 发生了什么……
# 给现有 topic 加 tag
topic = Topic.find id
Tag.create :name => 'tagname', :topic => topic
app/assets/javascripts/home.js.coffee
这个文件里面代码有错。
没看见有七牛相关的代码啊?
#27 楼 @woody1983 http://apidock.com/rails/ActiveRecord/Associations/ClassMethods/belongs_to
似乎是 :primary_key,我还没用过
belongs_to :person, :primary_key => "name", :foreign_key => "person_name"
如果你用默认的 id 做关联,就没必要经常更新外键了。
其实很明了了,AR 不支持更改 id,因为 id 的定义就是永远不改变的字段。
像订单号这样的数据应该另开一个字段,因为人工定义的字段没什么是不变的,身份证号就变过一次。
我不知道了,一个个 gem 去掉看看。
#23 楼 @woody1983 update_column 的意思就是脱离 AR 掌控更新一个字段
def update(attribute_names = @attributes.keys)
attributes_with_values = arel_attributes_values(false, false, attribute_names)
return 0 if attributes_with_values.empty?
klass = self.class
stmt = klass.unscoped.where(klass.arel_table[klass.primary_key].eq(id)).arel.compile_update(attributes_with_values)
klass.connection.update stmt
end
def arel_attributes_values(include_primary_key = true, include_readonly_attributes = true, attribute_names = @attributes.keys)
...
AR 特地吧 primary_key 排除了,就是不建议更新。一定要更新的话用 SQL 吧。