Rails 中缺少 'Show' 模板
Missing 'Show' Template in 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>
如有任何帮助,我们将不胜感激。这是一个非常简单的问题,我只是很难找到它。
我认为是 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"
"formats" 列表不包含 html
。您可以删除 defaults
选项,如果您的文件放置和命名正确,查找应该会成功。
无需在 routes.rb
中设置默认值:{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"
这是我的路线:
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>
如有任何帮助,我们将不胜感激。这是一个非常简单的问题,我只是很难找到它。
我认为是 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"
"formats" 列表不包含 html
。您可以删除 defaults
选项,如果您的文件放置和命名正确,查找应该会成功。
无需在 routes.rb
中设置默认值:{format: 'txt'}