Hello, good day!
This is a rather intricate question coming from a not so experienced ruby on rails user. Let’s get to it:
I am developing an app that has users, authors, microposts and tags. I want to implement something like a retweet button for the microposts:
The task is simple:
Get the params of a micropost(original user, original author, original tags)
“Retweet” it to my own wall, using these params, but also with my own user_id embedded in it.
So far I managed to “retweet” it, but there is one problem. As it is now, I am copying all the params and creating a new micropost with these params.
As this creates exact duplicate, I would like to know what would be the best approach to implement this function without creating replicas all over my app.
Here’s the codes:
resources :microposts do
original_micropost = Micropost.find(params[:id])
new_micropost = current_user.microposts.build(content: original_micropost.content, author_id: original_micropost.author_id)
flash[:success] = “Retweet Successful”
redirect_to user_path(current_user), notice: new_micropost.errors.full_messages
flash[:error] = “Retweet error!”
<%= link_to (image_tag “retweet.png”), retweet_micropost_path(micropost) %>
Let me know if there is anything else needed to get around this.
Thank you in advance.