微博:克隆 Twitter
1. Tweetclone 界面功能
1.1 直接消息的发送与显示
- 获取消息路由 :为了显示直接消息,创建了如下的获取消息路由:
get '/messages/:direction' do
load_users(session[:userid])
@friends = @myself.follows & @myself.followers
case params[:direction]
when 'received' then @messages = Status.all(:recipient_id => @myself.id); @label = "Direct messages sent only to you"
when 'sent' then @messages = Status.all(:user_id => @myself.id, :recipient_id.not => nil); @label = "Direct messages you've sent"
end
@message_count = message_count
haml :messages
end
此路由先获取用户的朋友列表(即关注该用户且被该用户关注的用户列表),然后根据请求的方向( received 或 sent )来获取相应的消息,并将消息发送到视图模板。
-
超级会员免费看
订阅专栏 解锁全文
4

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



