rails 2.3 的一個 bug?

class ForumPost < ActiveRecord::Base
  belongs_to :topic, :class_name => "ForumTopic"
  belongs_to :profile, :class_name => "ForumUserProfile"
  belongs_to :profile, :class_name => "ForumUserProfile", :foreign_key => "forum_user_profile_id"
  belongs_to :forum_user_profile, :class_name => "ForumUserProfile", :foreign_key => "forum_user_profile_id"
  def user
    self.profile.user
  end
end 

 3個belongs_to ,第一個無法運行,但是也不報錯。離譜的是運行時完全不激發SQL查詢語句,很奇怪。

 看來目前不能偷懶了,得把 foreign_key 補上。

 

還有個困惑就是belongs_to 是不能添加 :through 的,但是類似 aa belongs_to bb , bb belongs_to cc ,

通過aa 訪問 cc 難道只能 aa.bb.cc 來訪問?

現在暫時用的方法是用個方法來替代,不過總覺得不爽,肯定有方法的!

 

現在開始使用Rails 2.3 的新特性, NestedOjbectForum  , 確實滿好用。

注意的是一定要  model.more_models.build 下下,不然會出靈異事:field_for 表單消失了~~阿門,我可郁悶了好久,最後還是找教程才解決的。

 

附教程一篇,很基礎的。

http://ryandaigle.com/articles/2009/2/1/what-s-new-in-edge-rails-nested-attributes

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值