Link to most recent

Greetings all,

I have a side panel in my app that needs to have a link to the most
recent 4
or 5 items in a table. How do I create this link?

For example, I have a controller named widgets, and I want to create a
link
to :controller => “widgets”, :action => “show”, and then the most recent
id.
I want the text link to be the name of the widget.

Any ideas? Obviously, I’m another newbie…

James

James Collier wrote:

Greetings all,

I have a side panel in my app that needs to have a link to the most
recent 4
or 5 items in a table. How do I create this link?

For example, I have a controller named widgets, and I want to create a
link
to :controller => “widgets”, :action => “show”, and then the most recent
id.
I want the text link to be the name of the widget.

Any ideas? Obviously, I’m another newbie…

James

I have a side panel that shows the most recently viewed items (across
multiple controllers). For example, a user may have viewed a lead, an
order, etc… I want to show the most recent 10 items viewed. Here is
a sample of the shared view file used for the panel:

<% for viewitem in @view_items%>
<tr valign="top" class="ListRow1">
    <td width="25px" height="25px" align="right"><img alt="<%= 

viewitem.controller.pluralize %>" src="/images/<%=
viewitem.controller.pluralize %>.gif">


<%= link_to viewitem.value , :controller =>
viewitem.controller, :action => viewitem.action, :id => viewitem.item_id
%>

</tr>

<% end %>

My “view_items” are whatever your table is where the records are stored.
I store the name of the controller and the action in this table, but you
should be able to adjust accordingly. If this isn’t what you need then
please let me know and I’ll try to give a more specific example.

Regards,

Michael

On Tuesday, August 08, 2006, at 7:43 PM, James Collier wrote:


Rails mailing list
removed_ema[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails

==== controller ====

def sidebar
@most_recent_items = Item.find(:all, :order=>‘id DESC’, :limit=>5)

or use :order=>‘updated_at DESC’ if you have this field

end

==== view ====

<% for item in @most_recent_items %>
… display item …
<% end %>

_Kevin
www.sciwerks.com

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs