i have a Message model and controller. and in it, i have the standard functions such as index, show etc.
when i go to “localhost:3000/messages”, my index.html.erb gets displayed, which in turn renders my partial _messages.html.erb.
and in there, i have an anchor href
<a href= "received_messages">Received Messages</a>
however, i encounter 2 issues.
received_messages isn’t being appending the URL, which i thought it would normally do unless i added a / in the beginning. how do i make it append?
and also.. if i manually type in “localhost:3000/messages/received_messages”, i keep getting redirected to the messages#show function. why is that in general?
i have a received_messages.html.erb and even in my routes, i have
match '/received_messages', to: 'messages#received_messages'
which i have the function #received_messages in my controller as well.
why does it keep getting redirected to messages#show
thanks a lot = )
You asked:
In general, you have the idea of “messages”… and to
So, when you go to /messages/received_messages, the system, is attempting to show the message with id “received_messages”
If you want an action on the Collection of messages, you can setup your routes like:
This will match up “/messages/received”, and run the MessagesController#received action, and render the app/views/messages/received.html.erb file.