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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:39:41+00:00 2026-05-27T14:39:41+00:00

In index action of PostController @posts = Post.paginate(:per_page => 15, :page => params[:page], :order

  • 0

In index action of PostController

@posts = Post.paginate(:per_page => 15, :page => params[:page], :order => 'created_at DESC')

posts table

                                   Table "public.posts"
   Column    |          Type          |                     Modifiers                      
-------------+------------------------+----------------------------------------------------
 id          | integer                | not null default nextval('posts_id_seq'::regclass)
 title       | character varying(100) | not null
 content     | character varying(500) | not null
 created_at  | date                   | 
 updated_at  | date                   | 
 tags        | character varying(55)  | not null default '50'::character varying
 category_id | integer                | not null default 1
 user_id     | integer                | 
Indexes:
    "posts_pkey" PRIMARY KEY, btree (id)

users table

                                           Table "public.users"
         Column         |            Type             |                     Modifiers                      
------------------------+-----------------------------+----------------------------------------------------
 id                     | integer                     | not null default nextval('users_id_seq'::regclass)
 email                  | character varying(255)      | not null default ''::character varying
 encrypted_password     | character varying(128)      | not null default ''::character varying
 reset_password_token   | character varying(255)      | 
 reset_password_sent_at | timestamp without time zone | 
 remember_created_at    | timestamp without time zone | 
 sign_in_count          | integer                     | default 0
 current_sign_in_at     | timestamp without time zone | 
 last_sign_in_at        | timestamp without time zone | 
 current_sign_in_ip     | character varying(255)      | 
 last_sign_in_ip        | character varying(255)      | 
 confirmation_token     | character varying(255)      | 
 confirmed_at           | timestamp without time zone | 
 confirmation_sent_at   | timestamp without time zone | 
 username               | character varying(255)      | not null
 is_admin               | boolean                     | default false
 created_at             | timestamp without time zone | 
 updated_at             | timestamp without time zone | 
Indexes:
    "users_pkey" PRIMARY KEY, btree (id)
    "index_users_on_confirmation_token" UNIQUE, btree (confirmation_token)
    "index_users_on_email" UNIQUE, btree (email)
    "index_users_on_reset_password_token" UNIQUE, btree (reset_password_token)
    "index_users_on_username" UNIQUE, btree (username)

I need to get username from users table(need joining), not the user_id from posts table. I have used pagination in index.html.erb

Getting the username how can i display the username of a post in index.html.erb

  • 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-27T14:39:42+00:00Added an answer on May 27, 2026 at 2:39 pm

    just simple include should do the trick:

    @posts = Post.paginate(:per_page => 15, :page => params[:page], :order => 'created_at DESC', :include => :user)
    

    and then in the view:

    post.user.username
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am wondering how I can order posts in my PostController#index to display by
I've got a RESTful resource (let's say posts ) that excludes the index action.
I have a post html form, and the action is index.php, which is the
Here is my index.html.erb : <%= render :action => 'new' %> <% unless @posts.empty?
For example I have index action: def index @search = Product.search(params[:search]) @products = @search.all
My new controller action: controller do layout 'active_admin' def index @pages = Page.all end
i would like an index action to be able to take get and post
I want users to be redirected to the posts index action upon login. But
I have the following index action: class ExpensesController < ApplicationController def index() @expenses =
I would like that the Index action doesn't appear in the url. For example,

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.