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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:52:11+00:00 2026-05-26T21:52:11+00:00

I have the following model associations: class Product < ActiveRecord::Base has_many :prices class Price

  • 0

I have the following model associations:

class Product < ActiveRecord::Base
  has_many :prices

class Price < ActiveRecord::Base
  belongs_to :product

Here is my controller

class SearchController < ApplicationController

  # Using Sunspot here.
  def index
    @search = Product.search do
      fulltext params[:search]
      paginate(:per_page => 5, :page => params[:page])
    end
    @products = @search.results
  end
end

and then my view:

<%= will_paginate @products %>
<% @products.each do |product| %>
    <%= product.name %>
  <% prices.each do |price| %>
    <%= price.price %>
  <% end %>
<% end %>

Lets say I have 10 Products that each have 20 different Prices. My goal is to show 5 Products per page but have the Prices run over to the next page if the amount of Prices on a page exceeds a maximum of 25 at a time.

Here is two different examples of what I want it to do:

 Product 1, 2, 3, 4 + 5 Prices each = same page
 Product 5 + 6 Prices = this Product with Prices on next page

Or

Product 1 + 23 prices = same page
Product 2 + 20 prices = next page with Product and prices

How can I achieve this?

  • 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-26T21:52:12+00:00Added an answer on May 26, 2026 at 9:52 pm

    The first thing that comes to my mind is to query over the Price model:

    prices = Price.joins(:product).where(:product_id => [1,2,3]).paginate(:page => params[:page])
    

    And to make things easier for your views: prices.map! { |p| p.product }

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

Sidebar

Related Questions

I have the following models: class Price < ActiveRecord::Base belongs_to :product end class Metric
I have a model with the following associations: class Car < ActiveRecord::Base belongs_to :transportation_vehicle
I have the following model associations: class Slider < ActiveRecord::Base has_one :featured_happening, :as =>
I have the following models, with their relevant associations: class User < ActiveRecord::Base has_many
I have three classes with the following associations: class Technician < ActiveRecord::Base has_many :tickets
My system has the following associations set up: class Book < ActiveRecord::Base has_many :
I have got the following models, class City < ActiveRecord::Base belongs_to :state belongs_to :country
I have the following models: class Release < ActiveRecord::Base has_many :products, :dependent => :destroy
I have following model: class Customer < ActiveRecord::Base has_one :cart end class Cart <
I have the following models: class Aircon < ActiveRecord::Base belongs_to :shop belongs_to :brand belongs_to

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.