简体   繁体   中英

Post on a different page in ruby on rails

I have been trying to solve a problem for some time in ruby on rails, but I haven't been able to achieve it and I can't seem to find a solution online (it must be easy but I am not sure what is the write thing to search for)

So, in my web application, I have a CURD table and I use modal to create new items in there:

Image 1 Image 2

This is working perfectly fine. What I would like to do is that when this is created I'd like to post in a different page that " ABC have been created by X User"

In my case that would be the chatbox container: Image 3

So in my case, the green box is where I would like to say of what has been created and who has created it. I know that it is not a complex problem but I just can't seem to find the solution and I have been trying this for days.

Would really appreciate your help. Please let me know if you don't understand the problem and I can elaborate.

Thanks in advance.

Kind Regards,

Usman

You can create a separate model Notification (or similar name), and use an after_create hook in your original model to automatically create an instance of Notification . The Notification could store the information you want to display as attributes. From there, you'd have to figure out how to display the notification in the correct place on the 3rd page. One approach would be to query all your posts and notifications and sort them by created_at . There's other ways, it's up to you.

I get what you're saying.. but I am a little confused on the first part. So I have a model called Solr that has all the records associated with its User. What do I put in the after_create hook method to display records according to the timestamp in my Chat Box/ Events Log? Do you have an example of a similar implementation?

PS - Why do you say that I need to create a new model why can't I use the same model?

Thanks.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM