Application wide partial

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 '  ->>', { :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

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

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.

, 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

Alain R.

http://blog.ravet.com

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

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 '  ->>', { :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 '  ->>', { :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??