Forum: Ruby on Rails Admin links

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
11333f97a96662abe5d1e44fe1adf372?d=identicon&s=25 yaphi (Guest)
on 2009-03-02 18:03
(Received via mailing list)
Is there a better way to show admin link than this? I want to
implement page caching but can't due to it not having conditions.
Fragment caching seems wrong for my site since every page should be
cached except I have this toolbar div shown in the layout if the user
is logged in.

<% if logged_in? -%>
  <div id="admin">
    <ul>
      <li><%= link_to "New article", new_article_path %></li>
      <li><%= link_to "New project", new_project_path %></li>
      <%= yield :admin %>
      <li><%= link_to "Logout", logout_path %></li>
    </ul>
    <p class="flash"><%= flash[:notice] %></p>
  </div>
  <% end -%>

Any tips on a different way of doing the admin interface that don't
involve duplication like /admin/....?
D188e591eac11021329b8821a5f954c7?d=identicon&s=25 Ar Chron (railsdog)
on 2009-03-02 18:47
yaphi wrote:
> Is there a better way to show admin link than this? I want to
> implement page caching but can't due to it not having conditions.
> Fragment caching seems wrong for my site since every page should be
> cached except I have this toolbar div shown in the layout if the user
> is logged in.
>

So cache all your fragments...

one fragment is the toolbar div, the other fragment is the rest of the
page (effectively your 'page' caching).

I cache a left-nav fragment (effectively the admin versus not admin
menu), the main area fragment (for show or index, edit/new not cached),
and a right-nav fragment (a context menu of related models based on what
currently appears in the main area. the context-nav is itself a fragment
cache of multi-tiered fragments - the retrieval of all the related
models of a given model can be very expensive, so for a given model
instance, each type of related model has its own fragment). Takes a bit
to get used to for devs new to the project, but its easily an order of
magnitude faster to assemble fragments. Relating a new model just
invalidates that "related model type" fragment and the overall "related
models" fragment.
This topic is locked and can not be replied to.