Hi guys
I'm working on a social networking site (basically a copy of facebook to be honest...) and I reused big parts of insoshi. But the feed of insoshi is not accurate enough for my likings. As in it doesnt support more specialized messages. You will see what I mean in the following code:
item = activity.item
relationship = relationship(item)
case relationship
when 1
raw %(<p>You wrote on your own wall: <br/>
#{truncate(item.body, :length => 20)}</p>)
when 2
raw %(<p>#{link_to item.user.name, item.user} wrote on your wall</p>)
when 3
raw %(<p>#{link_to item.user.name, item.user} wrote on his wall</p>)
when 4
raw %(<p>You wrote on #{link_to item.user.name, item.user}'s wall</p>)
when 5
raw %(<p>#{link_to item.user.name, item.user} wrote on
#{link_to item.contact.name, item.contact}'s wall</p>)
end
def relationship(item)
unless item.owner.nil?
contact = item.owner #so that it works for posts as well
else
contact = item.contact
end
user = item.user
if current_user != contact or current_user != user
return 5
else
if current_user == contact
if current_user == user
return 1
else
return 2
end
else
if contact == user
return 3
else
return 4
end
end
end
end
I have different types of items. Normally items have a "user" and a "contact". Except posts, they have a "user" and an "owner". Because the other of a post can write it on somebody's wall (therefor the owner).
Now the problem arises as soon as I try to set the contact to the item.contact... it just keeps bugging me with 'NoMethod' error saying that item.contact does not exist. (which is obvious if the item is a post and not a 'connection' or comparable).
So I am asking for your opinion: 1) Fix the problem with some more ruby, or 2) change the post model so that a post has a 'user' and a 'contact'?
Thanks guys Stefano