Reputation: 6388
This code comes from the controller(class MainController < ApplicationController
) On console i can view the content from puts wallMessage.messagedestiny
and puts current_user.id
but on the next lines don't shows anything inside the sentence where the values are the same, here come the code:
Message.each do |wallMessage|
puts wallMessage.messagedestiny
puts current_user.id
if wallMessage.messagedestiny == current_user.id # <-- from here don't show anything from the following content in the sentence
puts "*** entra en el each y devuelve el wallMessage"
puts wallMessage
@wallMessages.push(wallMessage.messagecontent)
User.find_by(id: wallMessage.messagesender) do |messageSender|
@messageSenders.push(messageSender.username)
end
end
end
Upvotes: 0
Views: 31
Reputation: 11915
If the if
statement didn't get executed, its clear that the type
of the values don't match.
Try this and you can check if for yourself.
puts wallMessage.messagedestiny.class # displays the type of object
puts current_user.id.class
or
puts wallMessage.messagedestiny.class == current_user.id.class
You can convert the type
of one of the values to the other and compare them.
Upvotes: 1
Reputation: 6388
Solved!
if wallMessage.messagedestiny == String(current_user.id) # <-- Solution is convert to String cause current_user.id.class on console returned a BSON object
puts "*** entra en el each y devuelve el wallMessage"
puts wallMessage
@wallMessages.push(wallMessage.messagecontent)
User.find_by(id: wallMessage.messagesender) do |messageSender|
@messageSenders.push(messageSender.username)
end
end
Upvotes: 0