【发布时间】:2014-11-24 19:38:33
【问题描述】:
我的 Rails 4 应用程序中有两个资源 Category 和 Organization。我正在努力将局部变量与局部变量结合起来。
我有一个文件app/views/categories/_category.html.erb:
<li>link_to category.name, category</li>
在app/views/categories/show.html.erb 我可以使用渲染这个部分
<%= render @categories %>
要传递一个局部变量来表示,粗体显示列表中的当前类别,我可以将方法调用更改为
<%= render partial: "category", collection: @categories, as: :category, locals: {active_category: @category} %>
到目前为止一切顺利!代码做了我期望它做的事情。
但是当我想在文件app/views/organizations/show.html.erb 中为我的组织显示视图做同样的事情时,我遇到了问题。没有任何局部变量的原始渲染调用工作正常,即render @categories。然而,第二个电话给了我错误
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"
为什么会这样,我该如何解决?
【问题讨论】:
标签: ruby-on-rails-4 local-variables missing-template