Jadam
Jadam

Reputation: 1755

Missing Template on 404

I'm hitting a "Missing Template" error on a StandardError rescue I have in my application controller.

error message:

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

I've also tried being more explicit about the location of the 404 with render 'public/404.html' and render '/public/404' and render "{Rails.root}/public/404.html"

It's being hit from a before action on my users controller:

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

Upvotes: 1

Views: 2333

Answers (1)

Jadam
Jadam

Reputation: 1755

Turns out this was a product of rails 4.2 in which they have changed how you render with a string argument.

I did end up needing to add file: to my render but my string remained the original "public/404"

http://edgeguides.rubyonrails.org/4_2_release_notes.html#render-with-a-string-argument

Upvotes: 3

Related Questions