¿Cuál es la mejor práctica para restringir los enlaces de navegación en función del controlador y sus recursos anidados?

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?

preguntado el 27 de agosto de 11 a las 21:08

1 Respuestas

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?

Respondido 28 ago 11, 04:08

just didn't know if there was a better way than to have to check if the @account is not a new record every time... like maybe there was a better way to do this I was unaware of - GoodGets

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.