On Tue, May 4, 2010 at 3:16 PM, Chris Apolzon <[email protected]> wrote:
> 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

Couple things:

- the ||= here is not needed; controller instance variables (with an
@) are not persisted between requests.

- the search scope is extreme overkill here; you'll get a much more
efficient DB query (= rather than LIKE) with
status_is('seeking_reviewers'). OR, if the status is implemented as a
lifecycle (which it probably should be), then you'll get scopes like
seeking_reviewers for free.


> 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>

You might be better off defining a specific tag to handle this (the
DRY in DRYML):

<def tag="nav-item-with-count" attrs="status">
  <% link_text = parameters.default || status.humanize.titleize %>
  <% href = send("#{status}_manuscripts_path") %>
  <nav-item href="#{href}"><%= link_text %> (<%=
Manuscript.send(status).count %>)</nav-item>
</def>

This will simplify your main-nav to:

<nav-item-with-count status="received" />
<nav-item-with-count status="seeking_reviewers" />

Or, you can customize the link text:

<nav-item-with-count status="received">Some Other Title</nav-item-with-count>

Which will change the text, but keep the count in parentheses.

> And finally, is there a way to print an instance variable using the view:
> tag?

You can always do:

<view with="&@some_instance_var />

which should trigger the correct view tag.

--Matt Jones

-- 
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.

Reply via email to