Hey Fellow GoRailers,
I have a feature that I'm implementing and some guidance would be well appreciated.
It's linked posts: every time a posts gets updated, a link is placed on the original report to the (new) updated one.
The updated post is a brand new post (i.e. it has it's own view and URL, etc.) but it is related to other posts.
eg.) So the Product Hunt raises $1 million story, there was the original and say 5 updates. By the time the post is finished and no more updates will be added, the original post should have links to the other 5. Each of the other 5 should have links back to the original and the other stories.
So my thoughts where - using the after_update callback in my Post Controller, then past that updated record into a new Post object and link it via Post_id. I had problems thinking how to create the new post without it updated the original post.
Whilst typing this I remembered that the Ancestry gem may be used, and I could treat each updated message as a child node.
Ancestry is a great solution to the problem. To do this manually, you may want to instead change the
update action in your controller to:
This way your newest record will always be the most recent and each post can belongs_to it's parent post. In effect, you're just setting old record with a new parent each time you update it.
Join 30,005+ developers who get early access to new screencasts, articles, guides, updates, and more.