0

I'm trying to create a simple messaging capability for my User in my simple app.

So far, I've created a Message Controller/Model where users can simply message back and forth. User has_many :messages, and Messages belongs_to User.

My Message model is pretty simple. It has the sender ID, receiver ID, and message body.

In my Messages controller/views, I currently have the Index action where I display a simple line displaying that User has a new message. I want to add the functionality where the User can click on this line, which brings them to another Show page that displays the whole conversation between these 2 people. How do I add this specific route and corresponding action?

For example:

{root}/users/johnsmith/messages = shows the messages for john (this is working already) {root}/users/johnsmith/messages/sallyfields = shows conversation between john and sally

If someone can help, that'd be great! Thanks!!

gitastic
  • 516
  • 7
  • 26

1 Answers1

0

Those two routes are best represented by:

get 'users/:user_id/messages'     => 'messages#index'
get 'users/:user_id/messages/:id' => 'messages#show'

However this can also be represented by nested routes for a more restful effect:

resources :users do
  resources :messages
end