I''m not sure if this is what you''re asking but this is what
i''ve
implemented in a partial called _newest_date.rhtml :
<% if newest_date.created_at == newest_date.updated_at %>
<%= newest_date.created_at.strftime("Created on %m/%d/%Y") %>
<%= newest_date.created_at.strftime("at %I:%M%p") %>
<% else %>
<%= newest_date.updated_at.strftime("Updated on %m/%d/%Y") %>
<%= newest_date.updated_at.strftime("at %I:%M%p") %>
<% end %>
And i call this for every post that is shown in a page. With a little
more detail the list.rhtml file :
<% for post in @posts %>
<div class="post" id="post_<%= post.id %>">
<h3><%= link_to h(post.title), :action =>
''edit'', :id => post %></
h3>
<ul class="post_info">
<%= render :partial => ''newest_date'', :object =>
post %>
</ul>
[.... stuff here.....]
</div>
<% end %>
You could call a partial like this one from inside another partial.
I''m pretty sure this is NOT the best way to do it, but i''m
pretty new
at rails so this is a *fast* solution i found for my problem, which in
this case is to either print the created_at date or the updated_at
date according to which one is the newest.
P.S.: The controller just returns the @posts collection through a
paginator :
def list
@post_pages, @posts = paginate :posts, :order => ''id
DESC'', :per_page => 10
end
--Hope i helped a little
On May 1, 9:55 pm, josh
<rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:> Hi,
>
> I have partial:
> <%=render(:partial => ''blog_post'', :collection
=> @blogs)%>
>
> This outputs a series of blog posts, however I only want to output the
> created_on date if it is different from the last, is there a way to
> compare these or create a static variable that I can assign the date to?
>
> --
> Posted viahttp://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
-~----------~----~----~----~------~----~------~--~---