I've seen many posts about rescue_from ActiveRecord::RecordNotFound, :with => :record_not_found
, along with the companion method:
def record_not_found
redirect_to action: :show
end
This is my first time implementing this, so I'm wondering why I keep getting This webpage has a redirect loop
or that my params are incorrect for that route (within the record_not_found
method).
When a guest user time reaches a preset timeout limit, the user record will have the #destroy
method called on it--even if the guest is still within the app. The guest user has not yet inputted email/password, and the guest
column in the users
table is set to true
. (I actually want a guest to be able to Register w/ email, etc from within the app, transferring whatever data/dependencies the guest user object had acquired to the newly created permanent user.)
I've been putting them in my individual controllers, which I know is not DRY...I'd tried this in ApplicationController
and kept getting the This webpage has a redirect loop
, but I'm also now getting it in my individual controllers, so I guess that wasn't the problem.
Here is an example from my lessons_controller.rb
...
class LessonsController < ApplicationController
before_action :require_user, :only => [:show]
rescue_from ActiveRecord::RecordNotFound, :with => :record_not_found
def show
@lesson = Lesson.find(params[:id])
@assessment = @lesson.provide_assessment_object
if @assessment
@assessment.make_sure_choices_are_instantiated(current_user)
end
end
private
def record_not_found
redirect_to controller: :lessons, action: :show, id: params[:id]
end
end
My great preference would be to have all the record_not_found
methods (hopefully eventually all DRYed up within ApplicationController
) to redirect_to
the front
page which doesn't require a user session.
Any help on this would be most appreciate! Thanks a lot!