私は以下のモデルの関連付けを持っている:ここではこのように黒点をページ付けする方法は?
class Product < ActiveRecord::Base
has_many :prices
class Price < ActiveRecord::Base
belongs_to :product
は私のコントローラ
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
、その後、私の見解である:
<%= will_paginate @products %>
<% @products.each do |product| %>
<%= product.name %>
<% prices.each do |price| %>
<%= price.price %>
<% end %>
<% end %>
は、私は、それぞれが異なる20を持っている10社の製品を持っているとしましょう価格。私の目標は、1ページに5つの商品を表示することですが、ページ上の価格が一度に最大25を超える場合は、価格を次のページに引き継ぎます。
Product 1, 2, 3, 4 + 5 Prices each = same page
Product 5 + 6 Prices = this Product with Prices on next page
それとも
Product 1 + 23 prices = same page
Product 2 + 20 prices = next page with Product and prices
がどのように私はこれを達成することができます
ここで私はそれが何をしたいのかの二つの異なる例はありますか?
私は苦労以下をした、ことにします正直。まず第一に、「価格の高い製品」と「価格の多い製品(複数の!)」の両方があります。 – polarblau
@polarblau私は質問によってより明確にするために編集しました。 – LearningRoR