用户关注功能的实现与优化
1. 关系模型的验证
在进一步深入之前,为了保证完整性,我们需要为关系模型添加一些验证。以下是相关的测试代码和应用代码:
测试代码( spec/models/relationship_spec.rb )
describe Relationship do
describe "when followed id is not present" do
before { relationship.followed id = nil }
it { should not be valid }
end
describe "when follower id is not present" do
before { relationship.follower id = nil }
it { should not be valid }
end
end
应用代码( app/models/relationship.rb )
class Relationship < ActiveRecord::Base
attr accessible :followed id
belongs to :follower, class name: "User"
belongs to :followed, class name: "Us
超级会员免费看
订阅专栏 解锁全文

被折叠的 条评论
为什么被折叠?



