Use delegation in PostFake, use render => :collection in stream
This commit is contained in:
parent
6e7bdf7cad
commit
b7c3f93d25
2 changed files with 10 additions and 8 deletions
|
|
@ -4,8 +4,13 @@
|
||||||
|
|
||||||
|
|
||||||
- if posts.length > 0
|
- if posts.length > 0
|
||||||
- for post in posts
|
-# for post in posts
|
||||||
= render 'shared/stream_element', :post => post, :all_aspects => @all_aspects, :commenting_disabled => defined?(@commenting_disabled)
|
= render 'shared/stream_element', :post => post, :all_aspects => @all_aspects, :commenting_disabled => defined?(@commenting_disabled)
|
||||||
|
= render :partial => 'shared/stream_element',
|
||||||
|
:collection => posts,
|
||||||
|
:as => :post,
|
||||||
|
:locals => {:all_aspects => @all_aspects,
|
||||||
|
:commenting_disabled => defined?(@commenting_disabled)}
|
||||||
|
|
||||||
- else
|
- else
|
||||||
= render 'aspects/no_posts_message', :post_count => posts.length
|
= render 'aspects/no_posts_message', :post_count => posts.length
|
||||||
|
|
|
||||||
11
lib/fake.rb
11
lib/fake.rb
|
|
@ -1,13 +1,10 @@
|
||||||
class PostsFake
|
class PostsFake
|
||||||
attr_reader :people_hash, :post_fakes
|
attr_reader :people_hash, :post_fakes
|
||||||
|
delegate :length, :each, :to_ary, :to => :post_fakes
|
||||||
def method_missing(method, *args, &block)
|
|
||||||
@post_fakes.send(method, *args, &block)
|
|
||||||
end
|
|
||||||
|
|
||||||
def initialize(posts)
|
def initialize(posts)
|
||||||
person_ids = []
|
person_ids = []
|
||||||
posts.each do |p|
|
posts.each do |p|
|
||||||
person_ids << p.person_id
|
person_ids << p.person_id
|
||||||
p.comments.each do |c|
|
p.comments.each do |c|
|
||||||
person_ids << c.person_id
|
person_ids << c.person_id
|
||||||
|
|
@ -19,9 +16,9 @@ class PostsFake
|
||||||
people.each{|person| @people_hash[person.id] = person}
|
people.each{|person| @people_hash[person.id] = person}
|
||||||
|
|
||||||
@post_fakes = posts.map do |post|
|
@post_fakes = posts.map do |post|
|
||||||
f = Fake.new(post, self)
|
f = Fake.new(post, self)
|
||||||
f.comments = post.comments.map do |comment|
|
f.comments = post.comments.map do |comment|
|
||||||
Fake.new(comment, self)
|
Fake.new(comment, self)
|
||||||
end
|
end
|
||||||
f
|
f
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue