Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass all 4 parameters (message, model_name, query_field and id) to ActiveRecord::RecordNotFound.new when raising the exception. #890

Merged
merged 3 commits into from
Nov 22, 2018

Conversation

mri-dula
Copy link
Contributor

In my Rails App, I had written a common rescue for ActiveRecord::RecordNotFound in ApplicationController.

When this exception is rescued, I form a common error message:

rescue_from ActiveRecord::RecordNotFound, :with => :handle_404
def handle_404
    @exception = exception
    @not_found_message = "The #{@exception.model.name.underscore.humanize} you are looking for was not found"
     render :not_found
end

This worked fine when the model does not use FriendlyId.

In order to make this work with models that use FriendlyId, I have passed all four parameters (message, model_name, query_field and id) to ActiveRecord::RecordNotFound.new when it is being raised in finder_methods.rb.

@parndt parndt merged commit 877c096 into norman:master Nov 22, 2018
@parndt
Copy link
Collaborator

parndt commented Nov 22, 2018

Thank you @mridulap2003 🙌 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants