ruby on rails - How to make page error404? -
please advice.
userscontroller:
class userscontroller < applicationcontroller before_action :set_user, only: [:show] ........ ......... def show ...... end private def set_user @user = user.find_by_id(params[:id]) render_404 unless @user end end applicattioncontroller:
class applicationcontroller < actioncontroller::base before_action :set_locale protect_from_forgery with: :exception private def render_404 render file: "public/404.html", status: 404 end end at http://localhost:3000/users/24/ see page user.
at http://localhost:3000/users/24242424/ see page error404.
at http://localhost:3000/qwertyghjfd see error message:
routing error no route matches [get]
i need @ http://localhost:3000/qwertyghjfd saw page error404
in applicationcontroller call render_404 when there routing error
rescue_from actioncontroller::routingerror, :with => : render_404
Comments
Post a Comment