andi/simple-navigation — Issue #82: Procs used for :if conditionals are executed when nav is not rendered
Author: derekprior
Created: 2012-01-26 17:02:17+00:00
State: open

I have a multi-level navigation scheme similar to below:

```ruby
primary.item :schedule, 'Schedule', schedules_path do |schedule|
schedule.item :schedule_personal, 'My Schedule', '#', :if => Proc.new { current_user.has_schedules? }
schedule.item :schedule_weekly, 'Weekly Schedule', schedules_path, :highlights_on => :subpath
end
primary.item :admin, 'Admin', admin_root_path, :if => Proc.new { current_user.administrator? } do |admin|
admin.item :admin_shifts, 'Shifts', admin_shifts_path, :highlights_on => /admin\/?$|admin\/shifts/i
admin.item :admin_users, 'Users', admin_users_path, :highlights_on => :subpath
end
```

Notice the Proc called on the first schedule sub menu item. This proc is executed even when this particular sub menu is not executed. This particular proc results in a database query (albeit a fast one) every time its called. Every page in my application now executes this proc, despite it being necessary only when the schedule sub menu is being rendered.

Is there a way to prevent this?