Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6095719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:50:38+00:00 2026-05-23T12:50:38+00:00

My setup: Rails 3.0.9, Ruby 1.9.2 I am using Cancan to authorize a controller

  • 0

My setup: Rails 3.0.9, Ruby 1.9.2

I am using Cancan to authorize a controller action. If the user specify a missing id, then I have the following code

application_controller.rb

rescue_from ActiveRecord::RecordNotFound do |exception|
    flash[:alert] = "Oops, I cannot find this record, please try again."
        respond_to do |format|
            format.html { redirect_to root_url }
        end
    end

What I would like is for the above code to set the flash message to something like

flash[:alert] = "Oops, I cannot find this person, please try again."

“person” in this case could be any of the model, e.g, if the user tried to access a missing id for a country, it should say

flash[:alert] = "Oops, I cannot find this country, please try again".

You get the idea. I’m thinking I should be able to grab the originating call and controller, does anyone know how to do this or has a better way to do it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T12:50:39+00:00Added an answer on May 23, 2026 at 12:50 pm

    one thing you could do is to parse exception.message which usally contains a string looking like this

    “Couldn’t find Image with ID=03 [WHERE images.state = ‘published’]”

    but I would use the
    params object to access the controller and action causing the error

    like this:

        flash[:alert] = "Oops, I cannot find this #{params[:controller].upcase.singularize}, please try again."
    

    cheers

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple model setup in my Ruby on Rails app. (User {name,
I am using ruby on rails and have my database setup as follows in
I'm using Ruby on Rails to develop a web application. I have a wiki
I have Action Mailer setup to render an email using the body attribute of
My setup: Rails 2.3.10, Ruby 1.8.7 I'm using the will_paginate plugin and for a
I have done a lot of rails and ruby work in the past (using
I have an app that is using devise for authentication. Rails 3 on ruby
I am using Ruby on Rails 3.0.9 and I am trying to setup the
I am using Ruby on Rails 3.0.9 and I am trying to setup the
My setup: Rails 3.0.9, Ruby 1.9.2 I have my reasons for doing this but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.