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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:55:07+00:00 2026-06-02T07:55:07+00:00

I would like to be able to pass params to the is_following method as

  • 0

I would like to be able to pass “params” to the “is_following” method as follows:

       respond_to |format|
          format.json { render json: @user, :methods => [:is_following params] }
       end

However, when I put “params” after the method name, it throws an error:

syntax error, unexpected tIDENTIFIER, expecting ']'

.

.

When I render the JSON (without the is_following method), it looks like this:

[{"id":81,"image_url":"https://graph.facebook.com/123213123/picture?type=large","full_name":"John Johnson"},{"id":85,"image_url":"https://graph.facebook.com/123123123/picture?type=large","full_name":"Bill Nye"}]

I want to add the is_following method so that the JSON loos like this:

[{"id":81,"image_url":"https://graph.facebook.com/123213123/picture?type=large","full_name":"John Johnson",'is_following'=>4},{"id":85,"image_url":"https://graph.facebook.com/123123123/picture?type=large","full_name":"Bill Nye",'is_following'=>9}]

EDIT

def friends
  @user = User.first
  respond_to do |format|
    format.json { render json: @user.friends.order("first_name ASC"), :methods => [:is_following], :only => [:id] }
  end
end

and is_following method in model is:

def is_following params
    return Friendship.where("user_id = ? AND friend_id = ?", params[:user_id], self.id).count
end

Anyone know how to solve this? I will give you a million dollars.

  • 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-02T07:55:08+00:00Added an answer on June 2, 2026 at 7:55 am

    Brian,

    Just change this code:

    :methods => [:is_following params]
    

    to

    :is_following => is_following(params)
    

    EDIT

    Here is a better way to do this anyway:

    def friends
      @users = User.find_by_sql("SELECT users.*, 
          count(distinct friendships.friend_id) as is_following FROM users
          LEFT JOIN friendships ON users.id = friendships.user_id
          WHERE users.id = " + params[:user_id] + "
          GROUP BY users.id
          ORDER BY users.name ASC")
    
      respond_to do |format|
        format.json { render json: @users }
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a * -parameter method. I would like to be able to pass
i would like to be able to pass in a format string at runtime
What I would like to do is be able to pass any number of
Basically, I would like to be able to be able to pass a function_A
I would like to be able to pass an optional parameter to an ant
I would like to be able to pass an XML file to an ANT
I would like to be able to pass in the index of the image
I would like to be able to pass a parameter in a callback, but
I would like to be able to pass in rider or something else and
I would like to be able to pass extra arguments to a function and

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.