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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T00:53:28+00:00 2026-05-19T00:53:28+00:00

I have just begun Rails 3. I have generated the below code using the

  • 0

I have just begun Rails 3. I have generated the below code using the scaffold from Rails 3 on a table called “Logs”.

The ‘index’ function below provides only the records associated with the current_user.id (from the session stored in the session table). The users records are only presented with the following route logged in as user = 3 (see index code below)

localhost:3000/logs

Problem: As a user, I can view a record which is not my record (being user=3) by editing the url manually to show any other record:

localhost:3000/logs/5 ‘this was entered by user.id=2’

Seeking Solution: How do I prevent manually hacking of the url to prevent a user viewing other user records?

class LogsController < ApplicationController

before_filter :login_required

def index 
  @logs = Log.where(:user_id => current_user)
  respond_to do |format|
  format.html # index.html.erb
  format.xml  { render :xml => @logs }
end

Please ignore that the new function is missing from the create function below. The code below is to merely demonstrate how I put the user_id into the “Logs” table

def create
 @log = Log.new(params[:log])
 @log.user_id = current_user.id
  respond_to do |format|
  if @log.save
    format.html { redirect_to(@log)}
    format.xml  { render :xml => @log, :status => :created, :location => @log }
  else
    format.html { render :action => "new" }
    format.xml  { render :xml => @log.errors, :status => :unprocessable_entity }
  end
end
  • 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-19T00:53:29+00:00Added an answer on May 19, 2026 at 12:53 am

    The simplest solution would be to check in the show method if the Log to display really belongs to the logged in user:

    def show
      @log = Log.find(params[:id])
      unless @log.user_id == current_user.id
        flash[:error] = "unauthorized"
        redirect_to :index
      end
    end
    

    But you will soon have some more things you want to restrict access to, so you should look for an authentication plugin which allows to define the access rights in a declarative manner. Maybe this one: https://github.com/be9/acl9

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

Sidebar

Related Questions

I've just begun creating a rails application using mongomapper for my models. I'm wondering
I have just set up file uploads to Amazon S3 using Rails 3 and
I've recently began using dTrace and have noticed just how awesome it is. Its
Have just started using Google Chrome , and noticed in parts of our site,
Have just started using Visual Studio Professional's built-in unit testing features, which as I
I have just got a MacBook Pro and have been using it (+Fusion) to
I have just started using silverlight 2 beta and cannot find how to or
I have just started using Boost 1.36. These libraries would be very useful in
I have recently begun the process of trying to learn Ruby/Rails and have been
I have some trouble with using authlogic in my rails app, so I began

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.