I use this path: new_inspiration_path(inspiration_id: inspiration.id)
to take info from an existing inspiration and pre-populate a new form so a user can duplicate the inspiration just by clicking the path route and then submit.
But my problem is that once the form is submitted the new inspiration isn't created.
def new
if params[:inspiration_id]
@inspiration = Inspiration.find(params[:inspiration_id])
end
@inspiration = current_user.inspirations.build
end
def create
@inspiration = current_user.inspirations.build(inspiration_params)
@inspiration.save
end
This is because @inspiration is stuck trying to do two different things: .find
and .built
. How can we do both when params[:inspiration_id]
?
Question inspired by: How to prepopulate form with data passed from @object?