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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:11:16+00:00 2026-06-11T11:11:16+00:00

controller code: def create if current_user.id != params[:friend_id] @return = { :curr_user_id => current_user.id,

  • 0

controller code:

  def create

    if current_user.id != params[:friend_id]
      @return = { :curr_user_id => current_user.id, :params_id => params[:friend_id], :debug => 1 }
    else
      @return = { :curr_user_id => current_user.id, :params_id => params[:friend_id], :debug => 2 }
    end

    render :json => ActiveSupport::JSON.encode( @return )

  end

so current_user.id is 1 and params[:friend_id] is being passed via an ajax call and its value is also 1

the problem is that it always returns true when it should return false in this case… is there anything that has to do with the number 1 being parsed as string instead of integer?

  • 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-06-11T11:11:18+00:00Added an answer on June 11, 2026 at 11:11 am

    params are always strings, use:

    if current_user.id != Integer(params[:friend_id])
    

    I don’t recommend to_i, look why:

    "abc".to_i     # => 0 which is unexpected
    Integer("abc") # => raises error, which is fine
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code : def create login(params[:email], params[:password]) if current_user flash[:notice] = Welcome
def create msg = current_user.msgs.build(params[:msg]) msg.message = msg.message msg.created_at = Time.now # HACK if
I have this part of code: def create @post = Post.find(params[:post_id]) @comment = @post.comments.create(params[:comment])
My Controller (User Controller) def reset_password @user = User.find_by_reset_code(params[:reset_code]) unless params[:reset_code].nil? if request.post? if
My Controller (User Controller) def reset_password @user = User.find_by_reset_code(params[:reset_code]) unless params[:reset_code].nil? if request.post? if
In controller code, I have data in json format data = { 1: {assetId:1,status:true},
I'm attempting to debug a grails application and when I change controller code (method
In my create action, method new acts like create. def create @page = Page.new(params[:page].merge(:user_id
I have the following code in my controller: # GET /kases/1/edit def edit @kase
This is the code I have at the end a the create method in

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.