我正在尝试将contacts
分页部分放在rooftops
. Rooftops 有很多联系人,并且还有一个嵌套路由允许/rooftops/1/contacts
. will_paginate
当我尝试创建/rooftops/1
作为路径而不是“/rooftops/1/contacts/”的链接时。
有没有办法在不创建我自己的分页链接视图的情况下修改分页路径?我已经尝试在这里为 will_paginate访问 rdoc,但它进入了一个 godaddy 页面。
有任何想法吗?
class Contact < ActiveRecord::Base
has_and_belongs_to_many :parents
has_and_belongs_to_many :rooftops
has_one :user
has_one :address, :as => :addressable, :dependent => :destroy
has_many :phone, :as => :phoneable, :dependent => :destroy
belongs_to :position
accepts_nested_attributes_for :address, :reject_if => lambda { |a| a[:street].blank? }
accepts_nested_attributes_for :phone, :reject_if => lambda { |a| a[:phone_number].blank? }, :allow_destroy => true
validates_associated :address, :phone, :position
validates_presence_of :lname
validates_presence_of :fname
validates_presence_of :email
validates_presence_of :position_id
def self.search(page)
paginate :per_page => 3,
:page => page
end
end
class RooftopsController < ApplicationController
def show
@rooftop = Rooftop.find(params[:id])
@contacts = @rooftop.contacts.search(1)
end
end
<div class='pagination'>
<%= will_paginate contacts %>
</div>
这会创建/rooftops/1
,我不知道如何强制它/rooftops/1/contacts
。
- - - - - - - - - - -编辑 - - - - - - - - - - -
我的路线是
resources :rooftops do
resources :contacts
end
我想我知道我的问题在哪里。由于我的搜索功能在模型内。我从来没有真正接触过contacts
控制器。我从控制器进行搜索并从视图中rooftops
调用部分。contacts
我会展示我的观点。
<div id='contacts' style='margin-top: 20px; border-bottom: 1px solid lightgrey;'>
<h4>Contacts <%= link_to "new", new_polymorphic_path([@rooftop, Contact]) %></h4>
<%= render :partial => 'contacts/contacts', :locals => { :object_type => @rooftop, :layer => 1 } %>
</div>
这是实际的部分。如您所见,它从未真正通过联系人控制器。这可能是我问题的根源吗?
<table>
<tr>
<th></th>
</tr>
<% @contacts.each do |contact| %>
<tr>
<td class='contact_mailer'>
<%= link_to image_tag('icons/gray_light/mail_12x9.png'), "mailto:#{contact.email}" %>
</td>
<td>
<div class='expandable layer_<%= layer %>' style='float: left'>
<%= link_to contact.fname.titleize + ' ' + contact.lname.titleize, polymorphic_path([object_type, @contact]), :class => "contact_name" %>
</div>
</td>
<td>
<%= image_tag 'icons/blue/key_stroke_8x8.png' %>
</td>
</tr>
<% end %>
</table>
<br />
<div class='pagination'>
<%= will_paginate @contacts %>
</div>
谢谢你的帮助。