Help with app structure

Philip Brodd
Thu, 18 Aug 2005 02:58:14 -0000

I''m a novice with a basic question about application structure that I
hope I can frame in a useful way.

The list view displays several journals with a list of their latest
issues'' articles. I want to put "previous,"
"latest," and "next" links
after each issue listing to let users navigate (ideally without a page
refresh, but I would be happy to get the navigation working and add
Ajax niceties later).

The code below works to show the latest issue of each journal, but I''m
stumped trying to figure out how to implement the navigation.  In
particular, my use of the latest_issue function seems to complicate
things, but it was the only way I could figure out how to display what
I have.  Also, I feel like I should be using partial templates for
rendering these things, but I''m struggling with how to divide
everything.

I hope I''ve provided enough code to help someone help me, and I hope
I''m not asking for too much here.  Thank you!

-Phil



# from archive_controller.rb
#
...
def list
   @journals = Journal.find(:all)
end
...


# from list.rhtml
#
...
<% for journal in @journals %>
<% issue = latest_issue(journal) %>
<div class="journal" id="journal<%= issue.journal.id
%>">
<%= issue.journal.title -%> for <%= issue.published_on
%>
<ol id="issue<%= issue.id %>">
  <% for article in issue.articles %>
<%= article.title %>
  <% end %>


<% end %>
...


# archive_helper.rb
#
module ArchiveHelper
   def latest_issue(journal)
      Issue.find(:first, :conditions => "journal_id
''#{journal.id}''", :order => "published_on
DESC")
   end
end