lib/ecrire/app/controllers/ecrire/theme_controller.rb in ecrire-0.24.1 vs lib/ecrire/app/controllers/ecrire/theme_controller.rb in ecrire-0.25.0
- old
+ new
@@ -1,13 +1,17 @@
module Ecrire
class ThemeController < ::ApplicationController
+ unless Rails.env.development?
+ rescue_from ActiveRecord::RecordNotFound, with: :redirect_home
+ rescue_from ActionController::RoutingError, with: :redirect_home
+ rescue_from ActionView::ActionViewError, with: :redirect_home
+ end
+
before_action :pagination, only: :index
protect_from_forgery except: :index
- helper_method :post, :posts
-
def index
respond_to do |format|
format.html
format.rss
format.json do
@@ -15,29 +19,20 @@
end
end
end
def show
- redirect_to :root and return if post.nil?
- redirect_to :root and return unless post.published?
- if post.titles.first != @title
- redirect_to post_path(post), status: :moved_permanently
- end
end
protected
- def posts
- @posts ||= Post.published.page(params[:page]).per(params[:per]).order('published_at DESC')
- end
-
- def post
- @title ||= Title.find_by_slug(params[:id])
- @post ||= @title.post
- end
-
def pagination
params[:per] ||= 10
params[:page] ||= 1
+ end
+
+ def redirect_home(exception)
+ flash[:errors] = t('errors.request.not_found')
+ redirect_to '/'
end
end
end