我在应用程序控制器中的StandardError拯救中遇到“丢失模板”错误。
错误消息:
Missing template Users/Jadam/workspace/streetheart/streetheart_rebuild/public/404.html with {:locale=>[:en], :formats=>[:html, :text, :js, :css, :ics, :csv, :vcf, :png, :jpeg, :gif, :bmp, :tiff, :mpeg, :xml, :rss, :atom, :yaml, :multipart_form, :url_encoded_form, :json, :pdf, :zip], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :jbuilder, :haml]}. Searched in:
* "/Users/Jadam/workspace/streetheart/streetheart_rebuild/app/views"
的ApplicationController:
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
def current_user
User.find_by(id: session[:id])
end
def logged_in_user
unless logged_in?
store_location
flash[:danger] = 'Please log in'
redirect_to login_path
end
end
class AccessDenied < StandardError
end
rescue_from AccessDenied, with: :serve_404
def serve_404
render 'public/404', status: :not_found, layout: false
end
end
我也尝试过更清楚地了解404的位置
render 'public/404.html'
和render '/public/404'
以及render "{Rails.root}/public/404.html"
我的用户控制器上的操作被点击:
class UsersController < ApplicationController
before_action :logged_in_user, only: [:create, :destroy]
before_action :update_authorization, only: [:update]
...
def update
set_user
if @user.update(user_params)
redirect_to @user, notice: "Profile was successfully updated"
else
render :edit
end
end
private
def set_user
@user = User.find(params[:id])
end
def user_params
params.require(:user).permit(:first_name, :last_name, :email, :password, :twitter, :instagram, :avatar, :avatar_cache)
end
def update_authorization
@user = User.find(params[:id])
raise AccessDenied unless current_user.admin? || @user.id == current_user.id
end
end
答案 0 :(得分:2)
原来这是rails 4.2的产品,它改变了你用字符串参数渲染的方式。
我最后需要将file:
添加到render
,但我的字符串仍然是原来的"public/404"
http://edgeguides.rubyonrails.org/4_2_release_notes.html#render-with-a-string-argument