【问题标题】:Missing 'Show' Template in RailsRails 中缺少“显示”模板
【发布时间】:2016-11-24 03:15:08
【问题描述】:

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

缺少模板联合/显示,应用程序/显示与 {: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>

任何帮助将不胜感激。这是一个非常简单的问题,我只是很难找到它。

【问题讨论】:

  • format: :txt 一开始是怎么进来的?
  • 如果包含format: :txt,Rails 将只查找.txt 文件,而您的文件是.html.erb,即format: :html,这是默认设置。

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


【解决方案1】:

我认为是 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 选项,如果您的文件放置和命名正确,则查找应该成功。

【讨论】:

    【解决方案2】:

    不需要在你的 routes.rb 中有默认值:{format: 'txt'}

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-04-26
      • 2015-09-08
      • 1970-01-01
      • 1970-01-01
      • 2011-08-21
      • 1970-01-01
      相关资源
      最近更新 更多