简体   繁体   中英

Get information from a parent controller

I'm trying to show a nav tab menu from "menupersonas" controller in a file called "top_layout.html.erb"

I'm trying to show that menu with a render but from "personas" and "personascorreos" views:

"/personas/4/edit" and "/personascorreos/index.html.erb"

this way:

<%= render file: "menupersonas/top_layout" %>

I clarify that "personas" has_many "personascorreos"

so the link in the menu(top_layout.html.erb) that I need to show is "link_to(persona_personastelefonos_path(persona))"

But I got this error: "undefined local variable or method `persona'"

I think know that the problem is that @personascorreos = @persona.personascorreos.all is not defined in menupersonas controller

But my question is: Is there a way to call that information from personascorreos without need to define it again in menupersonas ?

If you render a view from another (as any partial) the controller method isn't called.

I think you're missing the passing of locals when rendering the view. Try:

<%= render file: "menupersonas/top_layout", persona: @persona %>

or whatever defines the local that is missing from your rendered view.

GL & HF.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM