Reputation: 3281
i was wondering how to use ajax for messaging between 2 users. im not really sure how to go about doing it. i essentially want a /messages URL, and in it will have a 'sent messages' button and also a 'received messages' button. when a user clicks on 'sent messages', it'll show all the sent messages asynchronously, and likewise for 'received messages'.
i created two partials for showing each of them separately, but im kinda lost on what to put inside Message#index (where /messages gets displayed). what kind of form should i be putting in there? i read that since its my index function being called, i should have a responds_to for a .js inside the function and then create a file titled index.js?
sorry but this ajax is still new to me. thanks a lot for your help = )
Upvotes: 0
Views: 209
Reputation: 4113
It will be to complex to answer you how to build views, partials and controllers code, but I can show you the general concept about solving your problem.
This can be devided with next steps:
1. You have to provide a way for users to be registered in your system.
2. Each user should have access to controller (say, Messages).
3. Messages controller should have several actions to provide user create and send messages. Also you should have some index
-like action (and it's .js
representation) to show messages delivered to this user. To achieve this you can use polling for changes method
well shown here: Polling for changes. To create new message you don't actually need to use AJAX. It can be simple form for sending some text to action in your MessagesController. Message can be saved in database and then rendered on the index
view by 'polling for changes' technique.
I hope I gave you some clue to solve ypur problem.
Upvotes: 2