Frage

In my Rails app I have about 20 pages, out of which 10 have a public nav menu (for not logged in visitors) and 10 have an admin nav menu (for logged in visitors).

Of DRY reasons, I would like to

<%= render 'layouts/navigation_public' %>

and

<%= render 'layouts/navigation_admin' %>

from the layouts/application.rb.

But the conditionals for the two partials gets very long, i.e.

if params[:controller] == "users" && params[:action] == "show" || if params[:controller] == "static_pages" && params[:action] == "welcome"

etc.

Is there a more clever/concise way to include the two navigation partials?

War es hilfreich?

Lösung

Would be better if you have controller-namespaces This would give you Admin:: namespace

And apparently you can contain the views for admin /views/admin.

If you want to make it more precise as /views/public, you can define public namespace as well.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top