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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:49:43+00:00 2026-05-24T03:49:43+00:00

What does the @posts line do exactly? def index if params[:user_id] && params[:artist_id] @id

  • 0

What does the @posts line do exactly?

def index
    if params[:user_id] && params[:artist_id]
      @id = params[:user_id]
      @name = Artist.find(params[:artist_id]).name
      @posts  = Post.includes(:user).where('users.id' => @id).joins(:artists).where('artists.name' => @name) 
    end
end

It seems to give me this really long query: confused as to why it needs all this.

Thanks

Started GET "/users/example4/artists/22/posts" for 127.0.0.1 at 2011-07-29 16:34:48 -0700
      Processing by PostsController#index as HTML
      Parameters: {"user_id"=>"example4", "artist_id"=>"22"}
      Artist Load (0.2ms)  SELECT "artists".* FROM "artists" WHERE "artists"."id" = 22 LIMIT 1
      Post Load (0.5ms)  SELECT "posts"."id" AS t0_r0, "posts"."title" AS t0_r1, "posts"."content" AS t0_r2, "posts"."user_id" AS t0_r3, "posts"."created_at" AS t0_r4, "posts"."updated_at" AS t0_r5, "posts"."item_name" AS t0_r6, "posts"."a_name" AS t0_r7, "posts"."image" AS t0_r8, 
"posts"."collection_id" AS t0_r09, "posts"."featured_post" AS t0_r10, "users"."id" AS t1_r0, 
"users"."email" AS t1_r1, "users"."encrypted_password" AS t1_r2, "users"."reset_password_token" AS 
t1_r3, "users"."remember_token" AS t1_r4, "users"."remember_created_at" AS t1_r5, 
"users"."sign_in_count" AS t1_r6, "users"."current_sign_in_at" AS t1_r7, "users"."last_sign_in_at" 
AS t1_r8, "users"."current_sign_in_ip" AS t1_r9, "users"."last_sign_in_ip" AS t1_r10, 
"users"."created_at" AS t1_r11, "users"."updated_at" AS t1_r12, "users"."name" AS t1_r13, 
"users"."username" AS t1_r14, "users"."bio" AS t1_r15, "users"."avatar" AS t1_r16, 
"users"."cached_slug" AS t1_r17, "users"."bg_image" AS t1_r18, "users"."bg_tile" AS t1_r19 FROM
 "posts" INNER JOIN "artisanships" ON "posts"."id" = "artisanships"."post_id" INNER JOIN "artists" 
ON "artists"."id" = "artisanships"."artist_id" LEFT OUTER JOIN "users" ON "users"."id" = 
"posts"."user_id" WHERE "users"."id" = 0 AND "artists"."name" = 'bobby' ORDER BY posts.created_at 
DESC
      User Load (1.6ms)  SELECT "users".* FROM "users" WHERE "users"."id" = 7 LIMIT 1
    Rendered posts/artists.html.erb within layouts/application (275.3ms)
    Completed 200 OK in 481ms (Views: 316.4ms | ActiveRecord: 3.4ms)
  • 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-24T03:49:44+00:00Added an answer on May 24, 2026 at 3:49 am

    I’d recommend reading the AR querying guide if you haven’t yet.

    The code you’ve pasted is from a controller–and in that action, you’re asking for multiple things. That’s why multiple queries are taking place.

    This line:

    @name = Artist.find(params[:artist_id]).name
    

    is querying the artists table and getting the name attribute from the result

    While this line:

    @posts  = Post.includes(:user).where('users.id' => @id).joins(:artists).where('artists.name' => @name)
    

    has both an .includes and a .joins in it … that’s why all the querying is required. As long as you have proper indexes created in your table, it shouldn’t be a problem.

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

Sidebar

Related Questions

I have read in some of the ClickOnce posts that ClickOnce does not allow
Does anyone know how to initiate a POST request in a Grails applications using
Does anyone have some sample code showing how to POST to a URL using
I cant post the code (proprietary issues) but does anyone know what types of
First post, so here goes. I'm writing a script that does intelligent search and
I'm looking at some 3rd party code and am unsure exactly what one line
I'm curious, how come I get 404 error running this line: urllib2.urlopen(http://localhost/new-post#comment-29) While everything
map.resource :basket, :collection => { :checkout => :post } The above does not work
I find the Post notification and delegate function are very useful in iOS. Once
Does Google force employees who have offers from Facebook to leave immediately?

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.