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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:26:50+00:00 2026-05-24T11:26:50+00:00

How do I prevent accessing a specific set of records based on a session

  • 0

How do I prevent accessing a specific set of records based on a session variable?

i.e. I have a table of items with a user_id key, how do I filter access to the items based on user_id. I don’t want someone to be able to access /items/3/edit unless that item has their user id against it (based on session var)

update:
I am using the answer suggested by @fl00r with one change, using find_by_id() rather than find() as it returns a nil and can be handled quite nice:

@item = current_user.items.find_by_id([params[:id]]) || item_not_found

where item_not_found is handled in the application controller and just raises a routing error.

  • 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-24T11:26:50+00:00Added an answer on May 24, 2026 at 11:26 am

    Restrict access by fetching items through your current_user object (User should :has_many => :items)

    # ItemsController
    def edit
      @item = current_user.items.find(params[:id])
      ...
    end
    

    where current_user is kind of User.find(session[:user_id])

    UPD

    Useful Railscast: http://railscasts.com/episodes/178-seven-security-tips, TIP #5

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

Sidebar

Related Questions

I have created an .htaccess files that will prevent anyone from accessing a file
How do I prevent my users from accessing directly pages meant for ajax calls
I need to prevent Session Fixation , a particular type of session hijacking, in
Is there any way to prevent NPE when accessing a nested bean using commons-beanutils?
I want to prevent the robots from accessing URLs that end with /new .
I am trying to secure a controller action to prevent a user from accessing
I have a standalone Windows-NT based machine (not connected to any network) and I
In asp.net, c# web applciation, is it possible to prevent bots from accessing a
How can I prevent a user from accessing my app at example.appspot.com and force
How can I prevent a user from accessing a page when they are not

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.