【问题标题】:ActionView::MissingTemplate in Posts#show (Issues with Partials)ActionView::MissingTemplate in Posts#show(部分问题)
【发布时间】:2014-08-13 07:00:48
【问题描述】:

我四处搜索并发现与我所面临的错误类似的错误。但是,似乎我的错误是相同的,但不同的情况略有不同。

我正在尝试导航到 localhost:3000/posts/2 错误提示
ActionView::MissingTemplate in Posts#show 这是完整的错误截图http://screencast.com/t/alwZHL9bkcKH

在我的 post_controller.rb 我有这个

class PostsController < ApplicationController
  def index
    @posts = Post.all
  end

  def show
    @post = Post.find(params[:id])
  end
end

我有一个包含 _categories.html.erb 的部分文件夹 /views/categories。

<span class="badge"><%= category.name %></span>

如果我排除我的类别部分 _categories.html.erb 并将以下内容插入 show.html.erb

<% @post.categories.each do |category| %>
  <span class="badge"><%= category.name %></span>
<% end %>

效果很好。

导致此部分问题的问题是什么?为什么不能使用?

【问题讨论】:

    标签: ruby-on-rails ruby erb


    【解决方案1】:

    部分文件的名称应为singular

    _category.html.erb
    

    它在错误消息中甚至非常清楚地说明了这一点。

    【讨论】:

      【解决方案2】:

      Rails 正在 views/categories/ 中查找名为 _category... 的文件。将部分文件名更改为_category.html.erb

      【讨论】:

        猜你喜欢
        • 2014-08-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-11-28
        相关资源
        最近更新 更多