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

  • Home
  • SEARCH
  • 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 3222604
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:00:37+00:00 2026-05-17T16:00:37+00:00

In my permissions controller, I use Active record to look for a permission: @permission

  • 0

In my permissions controller, I use Active record to look for a permission:

@permission = Permission.find(params[:user_id])

If this returns a result I then look up the permission.name And pass this to my controller.

Problem is sometimes this does returna result, othertimes it does not. When it does not, it errors. How can I prevent that from occuring?

Use Case:
1. If the user does have a permission record, show it and let the user change it
2. If not, show they don’t have a permission record and allow the user to set a permission.

Thanks

  • 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-17T16:00:37+00:00Added an answer on May 17, 2026 at 4:00 pm
    @permission = Permission.find_by_id params[:user_id]
    

    The idea is that if you are using the “first param is the id” version of find, you know exactly what you are looking for, and if it isn’t there, thats a problem. If you use one of the more generic finder syntaxes (like find_by_field_name), the assumption is that if it isn’t there, that is an acceptable situation so just return nil.

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

Sidebar

Related Questions

could really use your help, understanding this complex rails issue I've been banging by
I am trying to get the controller and action name based on a path.
I'm running into problems defining user permissions in my cancan controller: class Ability include
i was hoping to use grep to check and see if permissions have been
I can't understand why I have to use chmod to get the correct permissions..
If I grant execute permissions to a role via GRANT EXECUTE ON [DBO].[MYPROC] TO
Does anyone know which permissions are required for refreshing or connecting to linked tables
How can I check file permissions , without having to run operating system specific
I need to add role based permissions to my Rails application, and am wondering
How do you store file permissions in a repository? A few files need to

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.