# Application wide partial

**URL:** <https://www.ruby-forum.com/t/application-wide-partial/104501>\
**Category:** Rails\
**Created:** [May 18, 2007, 6:52pm UTC](https://www.ruby-forum.com/t/application-wide-partial/104501 "2007-05-18T18:52:15Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![freewolf](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/90db22/32.png) [@freewolf](https://www.ruby-forum.com/u/freewolf)\
**Post date:** [May 18, 2007, 6:52pm UTC](https://www.ruby-forum.com/t/application-wide-partial/104501/1 "2007-05-18T18:52:15Z")

</div>

I am having trouble find the answer that i need around partials for what  
I need.

In my app I am displaying tabular data over many different controllers.  
And I am displaying pagination links across the bottom of all of them.  
I want to pull it out into a partial or a helper (not sure the best  
here)

What I have currently looks like.

\<% if @payment\_pages.page\_count \> 1 %\>  
  
Page: \<%= link\_to '\< @payment\_pages.current.previous } if @payment\_pages.current.previous %\> \<%= pagination\_links @payment\_pages %\> \<%= link\_to '&nbsp;&nbsp;-\>\>', { :page =\> @payment\_pages.current.next } if @payment\_pages.current.next %\> \<% end %\>

I want to pull this out now into a place any view can use. But the  
@payment\_pages will obviously change based on what the controller is.

\<%= render\_collection\_of\_partials “partials/page\_links”, @payment\_pages  
%\>

How would I go about doing this??

Thanks

Phillip

---

<div class="post-metadata">

**Author:** ![freewolf](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/90db22/32.png) [@freewolf](https://www.ruby-forum.com/u/freewolf)\
**Post date:** [May 18, 2007, 8:19pm UTC](https://www.ruby-forum.com/t/application-wide-partial/104501/2 "2007-05-18T20:19:03Z")

</div>

Phillip,

> I want to pull this out now into a place any view can use.

The standard way it to move your partial to a “shared” directory

…/views/shared/\_your\_partial.rhtml

, and then in your controllers:  
render :partial =\> “shared/your\_partial”

## – Alain R.

[http://blog.ravet.com](http://blog.ravet.com)

---

<div class="post-metadata">

**Author:** ![freewolf](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/90db22/32.png) [@freewolf](https://www.ruby-forum.com/u/freewolf)\
**Post date:** [May 18, 2007, 8:25pm UTC](https://www.ruby-forum.com/t/application-wide-partial/104501/3 "2007-05-18T20:25:13Z")

</div>

Alain R. wrote:

> Phillip,
> 
> > I want to pull this out now into a place any view can use.
> 
> The standard way it to move your partial to a “shared” directory
> 
> …/views/shared/\_your\_partial.rhtml
> 
> , and then in your controllers:  
> render :partial =\> “shared/your\_partial”

Thanks.  
My bigger question is how to pass the variables to it and have it  
function properly.

Some pages my have @payment\_pages that need to get passed another might  
have @expenditure\_pages for example.

---

<div class="post-metadata">

**Author:** ![freewolf](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/90db22/32.png) [@freewolf](https://www.ruby-forum.com/u/freewolf)\
**Post date:** [May 18, 2007, 8:28pm UTC](https://www.ruby-forum.com/t/application-wide-partial/104501/4 "2007-05-18T20:28:05Z")

</div>

> > , and then in your controllers:  
> > render :partial =\> “shared/your\_partial”  
> > My bigger question is how to pass the variables to it and have it

The standard way, with :  
:locals =\> {:var1=\> value, …}

## See: [Peak Obsession](http://api.rubyonrails.com/classes/ActionController/Base.html#M000267)

## Alain R.

[http://blog.ravet.com](http://blog.ravet.com)

---

<div class="post-metadata">

**Author:** ![freewolf](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/90db22/32.png) [@freewolf](https://www.ruby-forum.com/u/freewolf)\
**Post date:** [May 19, 2007, 12:04am UTC](https://www.ruby-forum.com/t/application-wide-partial/104501/5 "2007-05-19T00:04:31Z")

</div>

Phillip,

(I don’t use the Rails’ paginator; I wrote my own one.)

> \<% if @page\_links.page\_count \> 1 %\>
> 
> =\> error message :  
> You have a nil object when you didn’t expect it!  
> The error occurred while evaluating nil.page\_count

As the message says: @page\_links is nil =\> you didn’t initialize it.

## – Alain R.

[http://blog.ravet.com](http://blog.ravet.com)

---

<div class="post-metadata">

**Author:** ![freewolf](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/90db22/32.png) [@freewolf](https://www.ruby-forum.com/u/freewolf)\
**Post date:** [May 18, 2007, 10:40pm UTC](https://www.ruby-forum.com/t/application-wide-partial/104501/6 "2007-05-18T22:40:24Z")

</div>

What am I missing here.  
Being new, I know what I want but am still learning the ROR syntax.  
Thanks for your help so far.

I have this code in the controller  
@expenditure\_pages, @expenditures = paginate :expenditures,  
:per\_page =\> 30, :order\_by =\> ‘date, expenditure’  
render\_action ‘list’

(similar code is repeated in a number of contollers)

In my list.rhtml file I have

\<%= render :partial =\> “shared/page\_links”, :collection =\>  
@expenditure\_pages %\>

In the page links file I have tried this

\<% if :page\_links.page\_count \> 1 %\>  
  
Page: \<%= link\_to '\< page\_links.current.previous } if page\_links.current.previous %\> \<%= pagination\_links page\_links %\> \<%= link\_to '&nbsp;&nbsp;-\>\>', { :page =\> page\_links.current.next } if page\_links.current.next %\> \<% end %\>

This will give me the following error.  
undefined method `page\_count’ for  
#ActionController::Pagination::Paginator::Page:0x46c9dc4

If I try

\<% if @page\_links.page\_count \> 1 %\>  
  
Page: \<%= link\_to '\< @page\_links.current.previous } if @page\_links.current.previous %\> \<%= pagination\_links @page\_links %\> \<%= link\_to '&nbsp;&nbsp;-\>\>', { :page =\> @page\_links.current.next } if @page\_links.current.next %\> \<% end %\>

I get  
You have a nil object when you didn’t expect it!  
The error occurred while evaluating nil.page\_count

What am I missing here??
