I have a simple database where users can create a task. I would like the index page to show which users created which task The relationship between task and user is 1 user to many tasks. The task has a user_id foreign key. Users can only create a task when they are logged in via Devise.
My create controller is as follows but I don't know how to record the foreign key for that task i.e. the user that created it.
def create
@challenge = Challenge.new(challenge_params)
respond_to do |format|
if @challenge.save
format.html { redirect_to users_path, notice: 'Challenge was successfully created.' }
format.json { render :show, status: :created, location: @challenge }
else
format.html { render :new }
format.json { render json: @challenge.errors, status: :unprocessable_entity }
end
end
end
challenge_params