@sevenseacat is right but I believe you would have a route conflict that way:
/messages/:id
/messages/:username
Perhaps the route should be more like /user/:id/messages which would be a nested route of messages under user
resources :users do
resources :messages, only: [:index]
end
Run rake routes
to see the generated route. In your MessagesController, you will receive :user_id and easily be able to call:
User.find(params[:user_id]).messages
Make sure you have has_many :messages
working in your User model.