I'm creating a to-do list app and I want users to be able to create a list without logging in and only log in when they wish to save their list. Right now I'm using Devise, where I created a belongs_to association of the activity to the user. The save works if the user is logged in but not otherwise.
How can I allow users to add activities to the activities index without having them being logged in and have the activities be deleted on refresh unless they log in and save them?
Activities_Controller:
def create
@activity = Activity.new(activity_params)
authorize @activity
if user_signed_in?
@activity.user = current_user
if @activity.save
redirect_to activities_path
else
render :new
end
else
@activity = Activity.new(activity_params)
if @activity.save
redirect_to activities_path
else
render :new
end
end
end