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.
<div class="page_links" align="center">
<% if @payment_pages.page_count > 1 %>
<br /><br />Page: <%= link_to
''<<- '', { :page =>
@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 %>
</div>
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
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
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 Ravet -------- http://blog.ravet.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Alain Ravet 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. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> > , and then in your controllers: > > render :partial => "shared/your_partial" > My bigger question is how to pass the variables to it and have itThe standard way, with : :locals => {:var1=> value, ..} See: http://api.rubyonrails.com/classes/ActionController/Base.html#M000267 -- Alain Ravet -------- http://blog.ravet.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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
<div class="page_links" align="center">
<% if :page_links.page_count > 1 %>
<br /><br />Page: <%= link_to
''<<- '', { :page =>
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 %>
</div>
This will give me the following error.
undefined method `page_count'' for
#<ActionController::Pagination::Paginator::Page:0x46c9dc4>
If I try
<div class="page_links" align="center">
<% if @page_links.page_count > 1 %>
<br /><br />Page: <%= link_to
''<<- '', { :page =>
@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 %>
</div>
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??
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
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_countAs the message says: @page_links is nil => you didn''t initialize it. -- Alain Ravet -------- http://blog.ravet.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---