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 4096230
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T20:01:12+00:00 2026-05-20T20:01:12+00:00

I am trying to make a system where user can only see articles that

  • 0

I am trying to make a system where user can only see articles that he or she wrote.

In Articles controller, I put below line

@article = current_user.articles.find(params[:id])

where params[:id] is an article_id.

I just want to know how I can skip the error from displaying and just redirect to the :index action if article does not exist, or if user does not have permission to view it.
I put @article.nil? conditional statement after above find statement, but it seems that the find statement above produces the error immediately like below.

Couldn’t find Article with ID=1662 [WHERE (articles.user_id = 1)]

How can I resolve this problem?

  • 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-20T20:01:13+00:00Added an answer on May 20, 2026 at 8:01 pm

    ActiveRecord::Base.find always throws an exception if it does not find a record, this is intentional. You should only use find if you absolutely expect to have whatever it is you’re looking for. If you are rending a show action and can’t find the article, you should rescue that exception and render a 404 (Not found) instead of redirecting to index (technically).

    If you want to find something by it’s id attribute without forcing an exception, use the dynamic finder find_by_id which will return false if it doesn’t find a record with that id.

    Edit:

    Dynamic finders now have a different signature, find_by_id should now be:

    find_by :id, id_to_find

    See the new Rails Guide on Querying

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

Sidebar

Related Questions

I'm trying to make a simple event dispatcher system. To put it simply, I
I'm trying to make an application that allows the user to access some information
I'm trying to make a simple application form were user can input data like
I'm trying to put together a simple system for a user to generate a
I'm trying to a design for a system where the user can define their
I'm trying to make a system call in Python and store the output to
I'm trying to make a ticketing system, but there are a few ways of
Got a question for you all! I'm trying to make a navigation system for
I'm trying to make a chat history system. So every time a person says
Im trying to make something like this http://demos.99points.info/facebook_wallpost_system/ which is a comment system. I

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.