has_and_belongs_to_many - ensure only rows with there user_id are returned

class User < ActiveRecord::Base
   has_many :messages
end

Then you can do the following once you have a valid user.

@user.messages

Can that be used in the message contoller?

@user.messages