Ruby on rails 4 使用局部变量呈现集合时缺少模板
我的Rails 4应用程序中有两个资源类别和组织。我正在努力渲染与局部变量相结合的局部变量 我有一个app/views/categories/_category.html.erb文件: 要传递一个局部变量,即列表中当前类别的粗体,我可以将方法调用更改为Ruby on rails 4 使用局部变量呈现集合时缺少模板,ruby-on-rails-4,local-variables,missing-template,Ruby On Rails 4,Local Variables,Missing Template,我的Rails 4应用程序中有两个资源类别和组织。我正在努力渲染与局部变量相结合的局部变量 我有一个app/views/categories/_category.html.erb文件: 要传递一个局部变量,即列表中当前类别的粗体,我可以将方法调用更改为 <%= render partial: "category", collection: @categories, as: :category, locals: {active_category: @category} %> 这是为什
<%= render partial: "category", collection: @categories, as: :category, locals: {active_category: @category} %>
这是为什么?我该如何修复它?如果您试图在app/views/categories/\u category.html.erb中渲染相同的部分,则需要更改组织的show模板的渲染调用
render partial: "categories/category", collection: @categories, ...
app/views/organizations/show.html.erb模板将在app/views/organizations/_category.html.erb中查找文件。叹气,我知道我尝试过这样做,但我一定是在category视图或其他地方做的。不管怎样,现在它起作用了。谢谢
<%= render partial: "category", collection: @categories, as: :category, locals: {active_category: @category} %>
Template is missing
Missing partial organizations/_category, application/_category with {
:locale=>[:en],
:formats=>[:html],
:variants=>[],
:handlers=>[:erb, :builder, :raw, :ruby, :coffee]
}.
Searched in:
* "/home/snail/.rvm/gems/ruby-2.1.2/gems/web-console-2.0.0.beta4/lib/action_dispatch/templates"
* "/home/snail/work/PROJECTNAME/app/views"
* "/home/snail/.rvm/gems/ruby-2.1.2/gems/web-console-2.0.0.beta4/app/views"
* "/home/snail/.rvm/gems/ruby-2.1.2/gems/devise-3.4.0/app/views"
render partial: "categories/category", collection: @categories, ...