i am trying to access some nested attributes in a rails partial; let me explain my issue:
i wrote a simple messaging service according to the tutorial of dana mulder i mentioned in another question of mine. a user has_many conversations, and a conversation has_many messages. every conversation has a recipient and a sender and every message has a boolean read, which is set to false by default.
what i am trying to do is to write a simple function that iterates through every message a user got in a conversation he is involved in, checks if the last message a user recieved in a conversation is read == true and not send by himself to display a little knob beside the "messages" link in the navigation of my app.
What i basically want to check is (multiple lines for better readability):
<%= if current_user.conversations.all.messages.last.user_id != current_user.id && current_user.conversations.all.messages.last.read == false %>
Message link with bubble beside it
<% else %>
Message link
<% end %>
This syntax does not work .. How is it possible to iterate through every conversation a user is involved, check the last message of every conversation if its written by this user and if not if its already read?
while something like Conversation.last.messages.last.content is working,
current_user.conversations.all.messages.last.content is not.. i find it a bit confusing how the accessibility of rails models are working.
thanks in advance! i hope i was explaining me well enough.
Best Regards