Frequently when I'm dealing with controllers I have found the need to stop the current action and then show an error page. Currently I have a method to show my error page in application controller:
And then from another controller I can use it like this:
However I dislike having to include and return alongside my show_error method to ensure that nothing else is executed. Is there a cleaner way to do this without using return?
class ApplicationController < ActionController::Base def show_error msg render file: 'public/404.html', message: msg, layout: false end end
class BikesController < ApplicationController def inspect @bike = Bikes.find(params[:id]) show_error("You can't inspect a bike without wheels!") and return unless @bike.hasWheels? @similar_bikes = Bikes.similar_to(@bike) render "inspect" end end