今回は,
発言一覧画面の改良
今まで
自分とフォローしているユーザの発言のみを表示
@me = Tw::Models::User[:name=>request.env['REMOTE_USER']]
@users = Tw::Models::User.all
layout :default, :title=>'Tw' do
table.tw do
tr do
td(:colspan=>2) do
form :action=>'/words', :method=>'post' do
textarea '', :name=>'word.text', :cols=>80, :class=>'words'; br
input :type=>:hidden, :name=>'word.user_id', :value=>@me.id
input :type=>:submit, :value=>'Update'
end
end
end
tr do
td do
table.contents do
@words.each do |word|
is_me = (word.user.name==@me.name)
unless @me.following_users.map{|u|u.name}.include?(word.user.name) || is_me then
next
end
view :word, :summary, :word=>word, :is_me=>is_me
end
end
end
td do
table.friends do
tr do
th(:colspan=>2){"users"}
end
@users.each do |user|
next if user.name == @me.name
view :word, :show_user, :user=>user, :me=>@me
end
end
end
end
end
end
自分を判別するために1行目で
その発言は自分のものかどうか?
is_me = (word.user.name==@me.name)
自分のものなら変数is_
その発言は自分のものもしくはフォローしている人のものか?
unless @me.following_users.map{|u|u.name}.include?(word.user.name) || is_me
フォローしているユーザの一覧は
発言を表示するビューの呼び出し
view :word, :summary, :word=>word, :is_me=>is_me
発言表示のビューを改良する
templates/
発言表示用のビュー
tr(:class=>@is_me ? 'mywords':'words') do
td.name(:style=>'width:10%;') do
strong do
@word.user.name
end
end
td.word do
span.word{@word.text}
span.date{@word.created_on.strftime("%Y-%m-%d %H:%M") if @word.created_on}
end
end
呼ばれたビューの中のインスタンス変数は,