简体   繁体   中英

Ruby on Rails partials

Can anyone help me out with the following? I have a partial view named _menu.html.erb inside a shared folder in views folder. I am trying to render this view inside my pages like so

<%= render "shared/menu" %>

But i am getting the following error.

Missing partial shared/_menu with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :jbuilder]}

What am I doing wrong?

Thanks!

Put your menu.html.erb

here

app/views/shared/_menu.html.erb

and then render this with this line

<%= render :partial => "/shared/menu" %>

If you use just "render" with an argument, it's excpecting an ActiveRecord object, and will look for the "show" partial of this object, like this :

<%= render @user %> #this will render the "user/show" partial for @user

You can render a classical partial like this (without locals if you don't need any arguments) :

<%= render partial: "shared/menu", locals: {my_arg: my_val} %>

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