缺少'显示' Rails中的模板

时间:2016-07-20 19:02:29

标签: ruby-on-rails ruby ruby-on-rails-4 missing-template

我收到一条错误消息,说明

  

缺少模板联合/显示,应用/显示   {:locale => [:en],:formats => [:text],:variants => [],:handlers => [:erb,   :builder,:raw,:ruby,:coffee,:jbuilder]}。搜索范围:*   "项目/ PlanoSyndication /应用/视图"

这是我的路线:

Rails.application.routes.draw do

    get 'syndication/:name', to: 'syndication#show', defaults: {format: 'txt'}

end

这是我的模特:

class Syndication < ActiveRecord::Base
end

这是我的控制器:

class SyndicationController < ApplicationController

  def show
    @syndications = Syndication.find_by name: 'tour_urls.txt'
  end

end

并在views/syndication/show.html.erb坐着

<div>
  <%= @syndications.each do |syn| %>
    <%= syn.body %>
  <% end %>
</div>

非常感谢任何帮助。这是一个非常简单的问题,我发现它真的很麻烦。

2 个答案:

答案 0 :(得分:2)

我认为这是导致查找失败的defaults: {format: 'txt'}选项。

您可以在此错误中看到:

Missing template syndication/show, application/show with {:locale=>[:en], :formats=>[:text], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :jbuilder]}. Searched in: * "Projects/PlanoSyndication/app/views"

“格式”列表不包含html。您可以删除defaults选项,如果放置了文件,则查找应该会成功。命名正确。

答案 1 :(得分:0)

您的routes.rb

中不需要默认值:{format:'txt'}