Hi all,
I am trying to create a shared partial to be used for many different
controller views to display the next/prev links when pagination is
used.
I read the section in the API describing how to pass local variables
to sub templates, and then I tried the following...
The partial:
<% if @pages.current.previous || @pages.current.next %>
<ul class="next-prev">
<% if @pages.current.previous %>
<li><%= link_to ''Previous page'', { :page =>
@pages.current.previous } %></li>
<% end %>
<% if @pages.current.next %>
<li><%= link_to ''Next page'', { :page =>
@pages.current.next } %></li>
<% end %>
</ul>
<% end %>
And then an example of how I''d like to render it:
<%= render :partial => ''../next_prev'', {:pages =>
@user_pages} %>
Trying this, I am getting the following error:
SyntaxError in Users#index
compile error
(erb):24: syntax error
_erbout.concat(( render :partial => ''../next_prev'', {:pages
=>
@user_pages} ).to_s); _erbout.concat "\n"
So...
1) What''s my problem? ;) That is to say, I don''t understand
where I
went wrong between the API and my code.
2) Is there a spot for globally shared partials already mapped by
rails? In the absence of this knowledge, I have begun to put such
partials in /app/views/ with specialized ones still residing within''
particular view subdirectories.
Thanks!
On 10/2/05, Seth Rasmussen <seths.mailing.lists-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi all, > > I am trying to create a shared partial to be used for many different > controller views to display the next/prev links when pagination is > used. > > I read the section in the API describing how to pass local variables > to sub templates, and then I tried the following... > > The partial: > > <% if @pages.current.previous || @pages.current.next %> > <ul class="next-prev"> > <% if @pages.current.previous %> > <li><%= link_to ''Previous page'', { :page => @pages.current.previous } %></li> > <% end %> > <% if @pages.current.next %> > <li><%= link_to ''Next page'', { :page => @pages.current.next } %></li> > <% end %> > </ul> > <% end %> > > And then an example of how I''d like to render it: > > <%= render :partial => ''../next_prev'', {:pages => @user_pages} %> > > Trying this, I am getting the following error: > > SyntaxError in Users#index > > compile error > (erb):24: syntax error > _erbout.concat(( render :partial => ''../next_prev'', {:pages => > @user_pages} ).to_s); _erbout.concat "\n" > > So... > > 1) What''s my problem? ;) That is to say, I don''t understand where I > went wrong between the API and my code. > > 2) Is there a spot for globally shared partials already mapped by > rails? In the absence of this knowledge, I have begun to put such > partials in /app/views/ with specialized ones still residing within'' > particular view subdirectories.What version of Rails are you using? Be sure it''s 0.13.1. Are you sure that <%= link_to ''Previous page'', { :page => @pages.current.previous } % is correct? Generally you should pass in :controller or :action... I''m not sure if :page is valid here.
If it''s a syntax error, I''d wrap my parameters in parentheses
for sure.
<%= render(:partial => ''../next_prev'', {:pages =>
@user_pages}) %>
Also, it looks like you''re missing the :locals key:
<%= render(:partial => ''../next_prev'', :locals =>
{:pages =>
@user_pages}) %>
Cool idea, by the way. I might use that partial :)
Duane Johnson
(canadaduane)
On Oct 2, 2005, at 3:49 PM, Seth Rasmussen wrote:
> Hi all,
>
> I am trying to create a shared partial to be used for many different
> controller views to display the next/prev links when pagination is
> used.
>
> I read the section in the API describing how to pass local variables
> to sub templates, and then I tried the following...
>
> The partial:
>
> <% if @pages.current.previous || @pages.current.next %>
> <ul class="next-prev">
> <% if @pages.current.previous %>
> <li><%= link_to ''Previous page'', { :page
=>
> @pages.current.previous } %></li>
> <% end %>
> <% if @pages.current.next %>
> <li><%= link_to ''Next page'', { :page
=>
> @pages.current.next } %></li>
> <% end %>
> </ul>
> <% end %>
>
> And then an example of how I''d like to render it:
>
> <%= render :partial => ''../next_prev'', {:pages
=> @user_pages} %>
>
> Trying this, I am getting the following error:
>
> SyntaxError in Users#index
>
> compile error
> (erb):24: syntax error
> _erbout.concat(( render :partial => ''../next_prev'',
{:pages =>
> @user_pages} ).to_s); _erbout.concat "\n"
>
> So...
>
> 1) What''s my problem? ;) That is to say, I don''t
understand where I
> went wrong between the API and my code.
>
> 2) Is there a spot for globally shared partials already mapped by
> rails? In the absence of this knowledge, I have begun to put such
> partials in /app/views/ with specialized ones still residing
within''
> particular view subdirectories.
>
> Thanks!
> _______________________________________________
> Rails mailing list
> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>