title: Rails: will_paginate links generated in context of the controller (self)
body: <p>I'm using will paginate bootstrap like this:</p>
  
  <p>My model:</p>
  
  <pre><code>class Customer &lt; ActiveRecord::Base
  
    attr_accessible :city, :country, :name, :street, :zip
  
    //... more code
  
    has_many :contacts, :dependent =&gt; :destroy, :autosave =&gt; true
  
  end
  
  
  class Contact &lt; ActiveRecord::Base
    attr_accessible :name, :notice, :phone
  
    //... more code
  
    belongs_to :customer
  end
  </code></pre>
  
  <p>Gemfile:</p>
  
  <pre><code>gem "will_paginate-bootstrap"
  </code></pre>
  
  <p>Partial which is able to generate paginated output in contacts/_pageable_contacts.html.erb:</p>
  
  <pre><code>&lt;%
      contacts = contacts.to_a.paginate( :page =&gt; params[:page] || 1, :per_page =&gt; 5 )
  %&gt;
  &lt;%= render(:partial =&gt; 'contacts/contacts', :locals =&gt; {:contacts =&gt; contacts})%&gt;
  &lt;%= will_paginate contacts, renderer: BootstrapPagination::Rails, remote: true %&gt;
  </code></pre>
  
  <p>Invocation inside contacts/create.js.erb:</p>
  
  <pre><code>&lt;%
  all = @contact.customer.contacts
  %&gt;
  &lt;%= render :partial =&gt; "contacts/pageable_contacts", :locals =&gt; { :contacts =&gt; all } %&gt;
  </code></pre>
  
  <p>The links generated by will_paginate are as follows as long as this partial has been rendered in context of the Contacts controller (e.g. views/contacts/create.js.erb):</p>
  
  <pre><code>customers/3/contacts?page=1
  customers/3/contacts?page=2
  </code></pre>
  
  <p>Now, I want to render this partial inside customer/show.html.erb like this:</p>
  
  <pre><code>&lt;%= render :partial =&gt; 'contacts/pageable_contacts', :object =&gt; @customer.contacts, :as =&gt; :contacts %&gt;
  </code></pre>
  
  <p>But the links returned by will_paginate are customer specific rather than contact specific. Apparently, will_paginate's accessing self (which is CustomerController) to build the links.</p>
  
  <pre><code>customers/3?page=1
  customers/3?page=2
  </code></pre>
  
  <p>How can I tell the partial or will_paginate howto deal with it? Did I misunderstand the concept of MVC, routes or anything else? Am I using the associations between the models in a wrong way?</p>
  
  <p>Any help appreciated!
  Thanks you SO.
  golbie</p>