I have a article/comments controller. When a user submits a comment and not logged in I want it to store in a session. After success login I want to create the stored comment.
What is the best way to do this?
btw: I got nested routes. articles => comments
so far i got:
class CommentsController < ApplicationController
def create
if current_user
create...
else
session[:comment] = params
redirect_to login_path
end
end
Preliminary note:
Instead of storing the params hash it is much better practice (and makes more sense) to create a comment that is not in a published state and store the ID in the session.
When you go to authenticate a user and the authentication is valid you can simply toggle that comment to be published using something like
Alternatively you could also redirect the user to a queue of their unpublished comments (you likely already redirect them to a dashboard page or something of the sorts).