I have some basic user navigation that only needs to be displayed if a user is viewing an Account, or any of its nested resources (members, contacts, etc). First thought would be to just check if there is an account instance
- if @account
= link_to 'members', account_members_path(@account)
but that would also enable the links on new account action, which is a no go. So, I’d need to hide the links if the @account is not a new record.
This works, but it’s ugly. I could place it in a helper
- if @account and @account.new_record? == false
But, is there a best practice to perform this check?
It’s common to move the menu into a partial and only render it inside the templates for the other actions.
For something this basic there isn’t a “best practice”, what you’re doing is easy to understand and works, what’s so bad about that?