3番目の条件への呼び出しを因数分解してFoo.find(params[:id])
使用できますexists?
module SomeHelper
def display_button
foo = foo.find_by_id params[:id]
foo and foo.organizer.name != current_name and foo.friends.where(:name => current_name).exists?
end
end
再利用性を高めるためにいくつかのメソッドを作成することもできます(モデルを変更した場合のトラブルを回避できます)。
module SomeHelper
def display_button
foo = foo.find_by_id params[:id]
foo && !is_organizer?(foo, current_name) && has_friend?(foo, current_name)
end
def is_organizer?(foo, name)
foo.organizer.name == name
end
def has_friend?(foo, name)
foo.friends.where(:name => name).exists?
end
end