我正确访问了网页https://lazyair.co/specials/2015-09-25-02
,
我确实有模板specials.html.haml
但它仍然显示ActionView::MissingTemplate
怎么会发生?任何方向?感谢
def specials
@specials = Special.all
end
An ActionView::MissingTemplate occurred in welcome#specials:
Missing template welcome/specials, application/specials with {:locale=>[:"zh-TW", :zh], :formats=>["image/webp", "image/*"], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :haml, :jbuilder]}. Searched in:
-------------------------------
Request:
-------------------------------
* URL : https://lazyair.co/specials/2015-09-25-02
* HTTP Method: GET
* Parameters : {"controller"=>"welcome", "action"=>"specials", "token"=>"2015-09-25-02"}
* Process: 7573
答案 0 :(得分:0)
您可以将路线限制为某些预定义格式,如下所示:
get 'specials/(:token)' => 'welcome#specials', :format => :html
get 'specials' => 'welcome#specials', :format => :html
有时此解决方案有效。但是,如果这不能解决您的问题,请尝试显式响应控制器操作中的格式:
def specials
@specials = Special.all
respond_to do |format|
format.html { }
end
end
答案 1 :(得分:0)
因为你的问题缺乏一些更精细的细节,所以我在做什么:
#app/controllers/welcome_controller.rb
class WelcomeController < ApplicationController
def index
@specials = Special.all
end
def show
@specials = Special.find params[:id]
end
end
#app/views/welcome/show.html.haml
...
#config/routes.rb
resources :welcome, path: "specials", only: [:show] #-> url.com/specials/:id
我理解这会改变方法名称(我更倾向于使用传统路由,而不是使用特殊方法名称)。它应该为您提供否定错误所需的结构。
此外,如果你在某种&#34;交易&#34;中使用它。应用程序,您将要执行以下操作:
#app/controllers/specials_controller.rb
class SpecialsController < ApplicationController
def index
@specials = Special.all
end
end
#app/views/specials/index.html.haml
<% @specials.each do |special| %>
<%= special.x %>
<% end %>