2016-07-20 62 views
0

我收到一條錯誤消息指出缺少 '顯示' 在Rails的模板

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"

這裏是我的路線:

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> 

任何幫助將不勝感激。這是一個非常簡單的問題,我只是很難找到它。

+0

如何做'格式:txt'在那裏得到擺在首位? – meagar

+0

如果包含'format :::txt',Rails只會查找.txt文件,而您的文件是'.html.erb',它是'format :::html',這是默認設置。 – hansottowirtz

回答

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選項,如果您的文件被正確命名爲&,則查找應成功。

0

沒有必要有默認值:{格式:「TXT」}在你的routes.rb