Well I managed to scrap something together. Here's my code:
[...snip...]
before_filter :setup_counts
def seeking_reviewers
hobo_index @seeking_reviewers ||= Manuscript.search("seeking_reviewers",
:status)
end
def at_review
hobo_index @at_review ||= Manuscript.search("at_review", :status)
end
def back_from_review
hobo_index @back_from_review ||= Manuscript.search("back_from_review",
:status)
end
def pending_resubmission
hobo_index @pending_resubmission ||=
Manuscript.search("pending_resubmission", :status)
end
private
def setup_counts
@received_count ||= (@received = Manuscript.search("received",
:status)).count
@seeking_reviewers_count ||= (@seeking_reviewers =
Manuscript.search("seeking_reviewers", :status)).count
@at_review_count ||= (@at_review = Manuscript.search("at_review",
:status)).count
@back_from_review_count ||= (@back_from_review =
Manuscript.search("back_from_review", :status)).count
@pending_resubmission_count ||= (@pending_resubmission =
Manuscript.search("pending_resubmission", :status)).count
end
And then, in my main-nav definition:
<nav-item href="&received_manuscripts_path">Received (<%= @received_count
%>)</nav-item>
<nav-item href="&seeking_reviewers_manuscripts_path">Seeking Reviewers (<%=
@seeking_reviewers_count %>)</nav-item>
<nav-item href="&at_review_manuscripts_path">At Review (<%= @at_review_count
%>)</nav-item>
<nav-item href="&back_from_review_manuscripts_path">Back From Review (<%=
@back_from_review_count %>)</nav-item>
<nav-item href="&pending_resubmission_manuscripts_path">Pending Resubmission
(<%= @pending_resubmission_count %>)</nav-item>
I'd love some criticism on my approach. Particularly, do I even need the
||= on the action definitions? Since setup_counts is run as a
before_filter, am I being overly cautious by safe-assigning the collection
variables again?
And finally, is there a way to print an instance variable using the view:
tag?
On Tue, May 4, 2010 at 2:41 PM, Chris Apolzon <[email protected]> wrote:
> I have some custom routes for my Manuscript controller; each route
> corresponds to a status filter. I would like to include the number of
> items in that view for each nav item.
>
> i.e.: (in manuscripts_controller.rb)
> def seeking_reviewers
> hobo_index Manuscript.search("seeking_reviewers", :status)
> end
>
> and the corresponding nav-item:
> <nav-item href="&pending_resubmission_manuscripts_path">Pending
> Resubmission</nav-item>
>
> I have no problem re-defining the nav-item definition (I already had
> to update how it handles the "current" class), but I'm not sure where
> I should pass the count from.
>
> Any help is most appreciated,
> Thanks.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Hobo Users" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<hobousers%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/hobousers?hl=en.
>
>
--
You received this message because you are subscribed to the Google Groups "Hobo
Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/hobousers?hl=en.