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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T01:49:25+00:00 2026-05-15T01:49:25+00:00

Hey guys I have a ruby on rails app with a before filter setup

  • 0

Hey guys I have a ruby on rails app with a before filter setup in my application controller to ensure only the owner can edit a document, but my permission check is always failing even when it shouldn’t. Here is the code:

def get_logged_in_user
  id = session[:user_id]
  unless id.nil?
    @current_user = User.find(id)
  end
end

def require_login
  get_logged_in_user
  if @current_user.nil?
    session[:original_uri] = request.request_uri
    flash[:notice] = "You must login first."
    redirect_to login
  end
end

def check_current_user_permission
  require_login
  logger.debug "user id is #{params[:user_id]}"
  logger.debug "current user id is #{session[:user_id]}"
  if session[:user_id] != params[:user_id]
    flash[:notice] = "You don't have permission to do that."
    redirect_to :controller => 'home'
  end
end

The code to note is in the check_current_user_permission. Here is an example of my log output:

user id is 3
current user id is 3
Redirected to http://localhost:3000/home
Filter chain halted as [:check_current_user_permission] rendered_or_redirected.

Can anyone shed some light into why this is failing? Obviously the user_id of 3 is equal to the session’s user_id of 3. What is going wrong?

  • 1 1 Answer
  • 1 View
  • 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-15T01:49:26+00:00Added an answer on May 15, 2026 at 1:49 am

    If session[:user_id] is ‘3’ and params[:user_id] is ‘3’ and they are not equal maybe you should .to_i them first?

    I only say this because I have this problem where I have two DateTime objects that when you .to_s them they are equal but for some reason that don’t evaluate to equal because somehow they are a fraction of a second different.

    Ruby is an awesome language but one draw back is the weakly typed features.. well its a double edged sword because weakly typed features allow for some cool stuff.

    Glad that helped!

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

Sidebar

Ask A Question

Stats

  • Questions 472k
  • Answers 472k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The answer is maybe. At some point, disk access will… May 16, 2026 at 3:47 am
  • Editorial Team
    Editorial Team added an answer Yes there is, you need -stringByAddingPercentEscapesUsingEncoding: method: [NSURL URLWithString:[string stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; May 16, 2026 at 3:47 am
  • Editorial Team
    Editorial Team added an answer IMHO I'd leave it the way it is, have the… May 16, 2026 at 3:47 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.