Forum: Ruby on Rails partial + custom class

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ed78f6c66a6f29bd89c67eeaf4f69931?d=identicon&s=25 Petr Bobek (praethorian)
on 2009-01-16 13:47
Hi all,

I am using partial:
<%= render :partial => 'post', :collection => @posts %>

_post.rhtml

<li>
    <p class="date"><em><%= post.created_at %></em></p>
    .
    .
</li>

this will display my last 4 posts next to each other, but each of this
<li> blocks have right-margin 33px and I would liko to set the last <li>
block with no right-margin. What I need to do is to add <li
class="last"> to last <li> block to not to set the right margin.

Any help would be most welcome.
Cheers P.
9b8d00f99fe595bdc45fd30439cf9c8f?d=identicon&s=25 Franz Strebel (Guest)
on 2009-01-16 13:51
(Received via mailing list)
On Fri, Jan 16, 2009 at 1:47 PM, Petr Bobek
<rails-mailing-list@andreas-s.net> wrote:
>
> Hi all,
>
> I am using partial:
> <%= render :partial => 'post', :collection => @posts %>
>
> _post.rhtml
>
> <li>
>    <p class="date"><em><%= post.created_at %></em></p>

You can use the last method of Array to figure out if you're on the last
post

<% if post == @posts.last -%>
Ed78f6c66a6f29bd89c67eeaf4f69931?d=identicon&s=25 Petr Bobek (praethorian)
on 2009-01-16 13:58
> <% if post == @posts.last -%>

Hi Franz,

works like a charm! Thank you.

P.
This topic is locked and can not be replied to.